Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am using a CGI file upload form that allows a bunch of formats. Is it possible to do a check to see if the file that's uploaded is an animation? Not talking about flash files, just animated images. I want to allow file uploads from guests, but animated files are a waste of space so I'm trying deny any attempted uploaded of this kind.

Replies are listed 'Best First'.
Re: CGI file uploads
by kvale (Monsignor) on Feb 27, 2004 at 04:50 UTC
    The animated image you are talking about are probably animated GIFs. An animated GIF is a file valid under the GIF89a spec, which you can get some info about here .

    The module Image::ParseGIF can break a GIF down into its component images and allow you to detect and reject animations.

    use Image::ParseGIF; $gif = new Image::ParseGIF ("image.gif") or die "failed to parse: $@\n +"; print "Multiple parts\n" if $gif->parts > 1;

    -Mark

      Thanks for your suggestion. I looked into that and I have 2 questions. First one being, is it possible to rearrange the frames with this module to create a brand new animation? Second being, is it possible for just a normal Perl/CGI function to figure out if it's animated or not? I don't mind using modules, but I doubt anyone who'd use my source has ever heard of or will have this module already installed.
Re: CGI file uploads
by waswas-fng (Curate) on Feb 27, 2004 at 04:55 UTC
    So if someone uploads a 20k animated gif, you don't want it. but a 200k gif is ok? =) just check the size of the gif and be done with it.


    -Waswas