A script to fetch images from a given url

The following Perl script periodically grabs images from a given url and stores them in the current directory naming the files according to the current time.

Image::Grab library is required (http://search.cpan.org/~mahex/Image-Grab-1.4.2/lib/Image/Grab.pod)


use strict;
use Image::Grab;

        sleep(15); # time to sleep before grabbing a new image

sub get_url(){
        my $pic = new Image::Grab;

        my $t = time;
        my $im = join('.', $t, "jpg"); # use the current time as an image filename
        open(IMAGE, ">$im") || die "$im: $!";
        binmode IMAGE;
        print IMAGE $pic->image;
        close IMAGE;

        my $filesize = -s $im;
        if ($filesize == 0){ # delete images with no content
                unlink $im;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License