If Media Type .GIF

Been looking for a way to do this but cant seem to find anything, not even here.

I am using timthumb to re-size my sites images. As most of you know after re-sizing a animated gif its not going to work any more. So i need a way to skip over the image if its a .gif file type. Something like

Read More
<?php if( typegif() ) { ?>
<img src="<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID),'full' ); echo $src[0]; ?>" alt="Image# <?php the_ID(); ?> "/> 
 <?php } else { ?>
 <img src="<?php bloginfo( 'template_url' ); ?>/thumbs/timthumb.php?src=<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); echo $src[0]; ?>&w=280" alt="Image# <?php the_ID(); ?> "/> 
 <?php } ?>

After some more digging i found this code, however its not working.

  $attachment_mime = wp_check_filetype(wp_get_attachment_url($post->ID) );
   if ( $attachment_mime['type'] == 'image/gif') { 
       echo 'this is gif';
       }
       else {
       echo 'this aint gif';
       }

Related posts

1 comment

  1. I’m not quite sure you’re using the wp_check_filetype() correctly. I just successfully tried the following to determine if the post thumbnail ext was jpg or not:

    $url = wp_get_attachment_url( get_post_thumbnail_id( ) );
    $filetype = wp_check_filetype($url);
        if ($filetype[ext] == 'jpg') {
            echo 'this is gif';
        }
        else {
           echo 'this aint gif';
        }
    

    You probably know already but if you ever want to see what the function returns, you can use echo print_r($filetype) and it will print the returned array and you can dissect how to best use the returned information (sometimes easier than interpreting up the codex!)

Comments are closed.