Posted By

Maximus1983 on 06/22/12


Tagged

library screen perl screenshots grab grabzit


Versions (?)

Capture Screenshots in Perl


 / Published in: Perl
 

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

Capture Web Screenshots easily with the GrabzIt Perl API

You will need the free GrabzIt Code Library to get started.

  1. #
  2. #The Perl file that takes the screenshot
  3. #
  4.  
  5. #!/usr/bin/perl
  6.  
  7. use GrabzItClient;
  8.  
  9. #Create the GrabzItClient class
  10. #Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
  11. $grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");
  12. #Take the picture the method will return the unique identifier assigned to this task
  13. $grabzIt->TakePicture("http://www.google.com", "http://www.example.com/GrabzItHandler.pl");
  14.  
  15. #
  16. #This GrabzItHandler file handles the GrabzIt callback
  17. #
  18.  
  19. #!/usr/bin/perl
  20.  
  21. use CGI;
  22. use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  23. use File::Spec;
  24. use GrabzItClient;
  25.  
  26. $cgi = new CGI;
  27.  
  28. $message = $cgi->param("message");
  29. $customId = $cgi->param("customid");
  30. $id = $cgi->param("id");
  31. $filename = $cgi->param("filename");
  32.  
  33. #Custom id can be used to store user ids or whatever is needed for the later processing of the resulting screenshot
  34.  
  35. $grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");
  36. $result = $grabzIt->GetPicture($id);
  37.  
  38. if ($result)
  39. {
  40. #Ensure that the application has the correct rights for this directory.
  41. open FILE, ">".File::Spec->catfile("images",$filename) or die $!;
  42. binmode FILE;
  43. print FILE $result;
  44. close FILE;
  45. }
  46.  
  47. print <<ENDOFTEXT;
  48. HTTP/1.0 200 OK
  49.  
  50. ENDOFTEXT
  51. exit(0);

Report this snippet  

You need to login to post a comment.