Search code examples
perlautomationscreenshot

How can I write a Perl script to automatically take screenshots?


  • I want a platform independent utility to take screenshots (not just within the browser).

  • The utility would be able to take screenshots after fixed intervals of time and be easily configurable by the user in terms of

    • time between successive shots,

    • the format the shots are stored,

    • till when (time, event) should the script run, etc

  • Since I need platform independence, I think Perl is a good choice.

a. Before I start out, I want to know whether a similar thing already exists, so I can start from there?

b. Which one of these Perl modules should I use?


Solution

  • Taking a look at the sources of both, Imager::Search isn't much more than a wrapper to Imager::Screenshot.

    Here's the constructor:

    sub new {
        my $class  = shift;
        my @params = ();
        @params = @{shift()} if _ARRAY0($_[0]);
        my $image = Imager::Screenshot::screenshot( @params );
        unless ( _INSTANCE($image, 'Imager') ) {
            Carp::croak('Failed to capture screenshot');
        }
    
        # Hand off to the parent class
        return $class->SUPER::new( image => $image, @_ );
    }
    

    Given that Imager::Search does not really extend Imager::Screenshot much more, I'd say you're looking at two modules that are essentially the same.