Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create an image of a web page in PHP?

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!

like image 573
B Seven Avatar asked May 03 '11 17:05

B Seven


People also ask

How will you create a image in PHP?

The imagecreate() function is an inbuilt function in PHP which is used to create a new image. This function returns the blank image of given size. In general imagecreatetruecolor() function is used instead of imagecreate() function because imagecreatetruecolor() function creates high quality images.

What is the first step to creating an image in PHP?

Creating the Image The first thing the code does is to call the imagecreate() function with the dimensions of the image, namely its width and height in that order. This function returns a resource identifier for the image which we save in $my_img . The identifier is needed for all our operations on the image.

How do you embed an image in a Web page in PHP?

To embed a PHP-generated image in an HTML page, pretend that the PHP script that generates the image is actually the image. Thus, if we have image1. php and image2. php scripts that create images, we can modify the previous HTML ...

Can we do images using PHP?

PHP is not limited to creating just HTML output. It can also be used to create and manipulate image files in a variety of different image formats, including GIF , PNG , JPEG , WBMP , and XPM .


1 Answers

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

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

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

like image 144
mario Avatar answered Sep 20 '22 01:09

mario