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

1 Answer 1

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!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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