GrabzIt's website screenshot API is very flexible and can be called in many ways. e.g. from a cronjob or a PHP web page. The best way to put website screenshots or HTML to image functionality into your PHP application is by following these steps:
To use our screenshot service you will first need to create an instance of the GrabzItClient class. Then pass your application key and application secret from your GrabzIt account to the constructor.
include("GrabzItClient.php"); // Create the GrabzItClient class // Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account! $grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
Then use one of the image, PDF, animation or table methods to capture a URL or convert HTML.
// To take a image screenshot $grabzIt->URLToImage("https://www.tesla.com"); // Or to take a PDF screenshot $grabzIt->URLToPDF("https://www.tesla.com"); // Or to convert online videos into animated GIF's $grabzIt->URLToAnimation("http://www.example.com/video.avi"); // Or to capture table(s) $grabzIt->URLToTable("https://www.tesla.com");
// To convert HTML into a image $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>"); // Or convert HTML into a PDF document $grabzIt->HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>"); // Or convert HTML into a CSV, XLSX or JSON document $grabzIt->HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr> <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr> </table></body></html>");
// To convert HTML file into a image $grabzIt->FileToImage("example.html"); // Or convert HTML file into a PDF document $grabzIt->FileToPDF("example.html"); // Or convert HTML file into a CSV, XLSX or JSON document $grabzIt->FileToTable("tables.html");
Next use one of the following save methods. As you can see with the Save method the URL to the handler.php is specified. This handler will process the callback from the service and save the resulting screenshot.
However if a publicly accessible callback handler is not available the synchronous SaveTo method should be used instead.
This will force your application to wait while the screenshot is created. So it should only be used were the Save method is not appropriate. Once the screenshot has been created it is automatically saved to the specified file path.
$filepath = "images/result.jpg"; $grabzIt->SaveTo($filepath);
When creating screenshots or converting HTML there are many more advanced options. Including: full page screenshots, configuring the browser width and height, image width and height. The delay before a screenshot is taken and the image format of the screenshot. However, creating PDFs, DOCX, Animated GIFs, CSVs and more is also supported. For all these options please see the Client documentation.