0

In a wordpress site, i have defined a default NOT_FOUND_IMAGE in timthumb config file:

// "http://example.com/timthumb-config.php".
<?php 
if(! defined('NOT_FOUND_IMAGE') ) define ('NOT_FOUND_IMAGE', 'http://example.com/img/default.jpg');

Is there any way to force resizing of this image depending on timthumb request parameters. For instance:

// 404 occurs
timthumb.php?src=http:%2F%2Fexample.com%2Fimg%2F404-image.jpg&h=180&w=120
// get resized (cropped) default image
timthumb.php?src=http:%2F%2Fexample.com%2Fimg%2Fdefault.jpg&h=180&w=120 
ramabarca
  • 298
  • 2
  • 14

2 Answers2

1

Try this code:

if (!defined('NOT_FOUND_IMAGE'))
  define ('NOT_FOUND_IMAGE','images/ingredient.jpg');
thanksd
  • 54,176
  • 22
  • 157
  • 150
0

I don't rate timbthumb, and I think it has security issues. Install and use the ThumbGen plugin instead.

You can then use it really easily with a normal editable conditional php statement.. (Pseudo)

<?php if you have a thumbnail { 
       Output the img with thumbgen resized
} else {
       Output the no image, you can even use thumbgen if you want
}
?>

Real world example:

<?php if ( has_post_thumbnail() )
        {
        $image_id = get_post_thumbnail_id();
        $alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
        $image_url = wp_get_attachment_image_src($image_id,'large');  
        $image_url = $image_url[0];
        ?>

            <img src='<?php thumbGen($image_url,175,175, "crop=1"); ?>' />

        <?php
        }

    else
        {
        ?>

            <img src="<?php bloginfo('template_url');?>/images/no-photo.png" alt="No Photo!">

        <?php
        }
?>
SMacFadyen
  • 3,145
  • 2
  • 25
  • 37
  • i need to handle 404 "not found image" error, with the same timthumb request parameters, specially **h={height}&w={width}**. I just can't use a "featured image" conditional handling. Thanks! – ramabarca Aug 25 '12 at 12:23