diff -u imagecache/imagecache.module imagecache.new/imagecache.module --- imagecache/imagecache.module 2011-05-16 13:12:33.000000000 -0400 +++ imagecache.new/imagecache.module 2011-06-15 10:34:01.000000000 -0400 @@ -856,6 +856,41 @@ } /** + * + * Determine if the image is animated + * + * @param + * $filename - name of file to path + * @return + * TRUE - if it is animated + **/ +function imagecache_is_animated($filename) { + $filecontents=file_get_contents($filename); + + $str_loc=0; + $count=0; + while ($count < 2) # There is no point in continuing after we find a 2nd frame + { + $where1=strpos($filecontents,"\x00\x21\xF9\x04",$str_loc); + if ($where1 === FALSE){ + break; + } else { + $str_loc=$where1+1; + $where2=strpos($filecontents,"\x00\x2C",$str_loc); + if ($where2 === FALSE) { + break; + } else { + if ($where1+8 == $where2) { + $count++; + } + $str_loc=$where2+1; + } + } + } + return ($count > 1); +} + +/** * Create and image tag for an imagecache derivative * * @param $presetname @@ -891,7 +926,13 @@ } $attributes = drupal_attributes($attributes); - $imagecache_url = imagecache_create_url($presetname, $path, FALSE, $absolute); + + $data = @getimagesize($path); + if (isset($data) && is_array($data) && $data['mime'] == 'image/gif') { + $animated = imagecache_is_animated($path); + } + + $imagecache_url = ($animated) ? '/'.$path : imagecache_create_url($presetname, $path, FALSE, $absolute); return ''. check_plain($alt) .''; }