Capture Screenshots in PHP


/ Published in: PHP
Save to your folder(s)

Capture Web Screenshots easily with the [GrabzIt ](http://grabz.it/) PHP API

You will need the free [GrabzIt Code Library](http://grabz.it/api/php/download.aspx) to get started.


Copy this code and paste it in your HTML
  1. /*
  2.  * The PHP file that takes the picture
  3. */
  4.  
  5. include("GrabzItClient.class.php");
  6.  
  7. //Create the GrabzItClient class
  8. //Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
  9. $grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");
  10. //Take the picture the method will return the unique identifier assigned to this task
  11. $id = $grabzIt->TakePicture("http://www.google.com", "http://www.example.com/GrabzItHandler.php");
  12.  
  13. /*
  14.  * The GrabzItHandler file that saves the picture
  15. */
  16.  
  17. include("GrabzItClient.class.php");
  18.  
  19. $message = $_GET["message"];
  20. $customId = $_GET["customid"];
  21. $id = $_GET["id"];
  22. $filename = $_GET["filename"];
  23.  
  24. //Custom id can be used to store user ids or whatever is needed for the later processing of the
  25. //resulting screenshot
  26.  
  27. $grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");
  28. $result = $grabzIt->GetPicture($id);
  29.  
  30. if (!$result)
  31. {
  32. return;
  33. }
  34.  
  35. //Ensure that the application has the correct rights for this directory.
  36. file_put_contents("images" . DIRECTORY_SEPARATOR . $filename, $result);

URL: http://grabz.it/api/php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.