Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Is this a mistake in code to check for animated GIF?

    I wish to use the code from the following page that can be used to check if an uploaded image is an animated GIF:
    http://stackoverflow.com/questions/2...ing-php-and-gd

    Here is the function:
    PHP Code:
    function is_ani($filename) {
        if(!(
    $fh = @fopen($filename'rb')))
            return 
    false;
        
    $count 0;
        
    //an animated gif contains multiple "frames", with each frame having a
        //header made up of:
        // * a static 4-byte sequence (\x00\x21\xF9\x04)
        // * 4 variable bytes
        // * a static 2-byte sequence (\x00\x2C)

        // We read through the file til we reach the end of the file, or we've found
        // at least 2 frame headers
        
    while(!feof($fh) && $count 2)
            
    $chunk fread($fh1024 100); //read 100kb at a time
            
    $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00\x2C#s'$chunk$matches);

        
    fclose($fh);
        return 
    $count 1;

    Am I right in saying that there are curly brackets missing after the while line? The indenting indicates that both of the 2 following lines should be included in the while loop, but the lack of curly brackets mean that only the line beginning with $chunk is included in the loop.

    The code actually seems to work with and without the curly brackets. Does anyone understand this code well enough to know whether or not the curly brackets should be included?

    Thanks in advance.

  • #2
    New Coder
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It seems to me like you would need the brackets. Is it possible it is working fine either way for you b/c you are processing files that are less than 100kb?

    I agree that the indentation is misleading if you don't need them. I don't see how the second line is possibly being executed in a file that is larger than 100kb....

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks tjfoz. You are right, the animated GIFs I was using were less than 100kb, which is why it appeared to work either way. I will make sure the brackets are added.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •