Use PHP to generate snapshot images and thumbnails for websites
This is required for comprehensive website information query.
I searched for foreign solutions.
Most of them are implemented using the API of the other party.
But this method is not good.
1. A watermark will be added to the target user. It is not good to add a watermark to the thumbnail.
2. There is a limit on the generation of free images. The charges are too high. Generally, $1 = 10 thumbnails can be generated.
Like me, generating more than million thumbnails is not very reliable. The cost is too expensive and the thumbnails are all watermark.
Finally, we decided to use third-party open-source software for self-building.
In this way, after a website snapshot is generated, it can be automatically uploaded to and called in the cloud.
No problem with this scheme for temporary Testing
Http://code.google.com/p/wkhtmltopdf/downloads/list
32-bit download
Wkhtmltoimage-0.11.0_rc1 Linux static binary (i368)
64-bit download
Wkhtmltoimage-0.11.0_rc1 Linux static binary (amd64)
This is a compiled static executable file, which is relatively simple and convenient.
Dependent on qt4 package
Extract
Tar-xvf **** .tar.bz2
Move the Directory and call PHP directly.
For example,/sbin/wkhtmltoimage
Test/sbin/wkhtmltoimage Google.com g.jpg first
We recommend that you set the definition to a low point.
I tested it. If not
The size of the PNG generated on the Google page is 1 MB or more. The size of JPG is 400 Kb or more.
In PHP, exec can be called to generate and then process the image.
Then, when using PHP gd or IM
PHP can use the GD or IM image processing module for processing.
Watermarks that can be added with thumbnails, etc.
Other open-source solutions are being tested.
Restful APIs
Update now
-------------------------------------
There are many websites outside China that provide the URL address preview function. move the cursor over the URL address to automatically display the thumbnail of the website.
I think it is appropriate to use wkhtmltopdf and provide windows, Linux, and Mac versions.
The detailed parameters of this tool are as follows:
General options:
-- Crop-H <int> set height for croping
-- Crop-W <int> Set width for croping
-- Crop-x <int> set X coordinate for croping
-- Crop-Y <int> set Y coordinate for croping
-H, -- extended-help display more extensive Help, detailing less common command Switches
-F, -- format <format> output file format (default is JPG)
-H, -- help display help
-- Quality <int> output image quality (between 0 and 100) (default 94)
-V, -- version output version information an exit
-- Width <int> set screen width (default is 1024) (default 1024)
---------------------------
Tar:
Http://code.google.com/p/wkhtmltopdf/downloads/list
Related Links
Http://blog.cnlabs.net /? P = 2625
Http://blog.cnlabs.net /? P = 2636
Http://brooky.cc/2011/05/26/convert-html-to-image-and-pdf/
Http://www.oschina.net/question/12_10653