How can you render and save a web page as an image in PHP, probably with a width of 600px. How can I render a page in PHP without using a browser? How can I save it with a given resolution and image format (jpeg)? The functionality is similar to Google Preview, except it will not be displayed in a rollover.
Similar to this question, which is answered in C#. How to save a web page as image
Thanks!
You can't do this in pure PHP, you'll always need an external renderer to get a good result.
Your best bet would be to use an external service such as the browsershots.org API, this way you won't produce extra load on your server.
If you have resources to burn, you could use another method (still running on your server, just not PHP) called wkhtmltoimage as in mario's answer. Just remember that this wouldn't be recommended (infact, probably not even possible) on shared hosting.
You should get
wkhtmltoimage
, which is very easy to utilize from within PHP:There are other options, and instead of
--crop-w
or--width 600
it might be better to downscale it using GD or imagemagick afterwards.