How to create a web page image in PHP?

How can you make and save a webpage as an image in PHP, possibly with a width of 600 pixels. How can I make a page in PHP without using a browser? How to save it with a given resolution and image format (jpeg)? The functionality is similar to Google Preview, except that it will not be displayed when rollover.

Similar to this question that C # answers. How to save a web page as an image

Thank!

+5
html php save render
May 03 '11 at 17:17
source share
2 answers

You should get wkhtmltoimage , which is very easy to use from PHP:

 exec("../wkhtmltoimage --crop-w 600 http://example.com/ output.png"); 

There are other options, and instead of --crop-w or --width 600 might be better to down scale using GD or imagemagick afterwards.

+7
May 03 '11 at 17:24
source share

You cannot do this in pure PHP, you will always need external rendering to get a good result.

Itโ€™s best to use an external service, such as the .org browser APIs , so you wonโ€™t put extra load on your server.

If you have the resources to write, you can use another method (still running on your server, not PHP) called wkhtmltoimage, as in mario answer . Just remember that this is not recommended (infact, perhaps not even possible) on shared hosting.

+2
May 03 '11 at 17:27
source share



All Articles