1

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

<?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';
       }
  • Wow did i find a question no one can answer lol – Noob Theory Nov 12 '13 at 16:48
  • If i misspelled the title wrong 5 people would have done commented by now. – Noob Theory Nov 15 '13 at 0:54
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!)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.