个性化阅读
专注于IT技术分析

timthumb NOT_FOUND_IMAGE调整大小

点击下载

在wordpress网站中, 我在timthumb配置文件中定义了默认的NOT_FOUND_IMAGE:

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

有什么方法可以根据timthumb请求参数来强制调整此图像的大小。例如:

// 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 

#1


试试这个代码:

if (!defined('NOT_FOUND_IMAGE'))
  define ('NOT_FOUND_IMAGE', 'images/ingredient.jpg');

#2


我不评价timbthumb, 并且认为它存在安全问题。安装并使用ThumbGen插件。

然后, 你可以通过普通的可编辑条件php语句轻松地使用它。(伪)

<?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
}
?>

真实的例子:

<?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
        }
?>
赞(0)
未经允许不得转载:srcmini » timthumb NOT_FOUND_IMAGE调整大小

评论 抢沙发

评论前必须登录!