【问题标题】:timthumb NOT_FOUND_IMAGE resizetimthumb NOT_FOUND_IMAGE 调整大小
【发布时间】:2016-01-30 13:36:14
【问题描述】:

在一个 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 

【问题讨论】:

    标签: wordpress image-processing wordpress-theming timthumb


    【解决方案1】:

    试试这个代码:

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

    【讨论】:

      【解决方案2】:

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

      然后,您可以通过正常的可编辑条件 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
              }
      ?>
      

      【讨论】:

      • 我需要使用相同的 timthumb 请求参数处理 404“未找到图像”错误,特别是 h={height}&w={width}。我只是不能使用“特色图像”条件处理。谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-15
      相关资源
      最近更新 更多