PHP - wordpress中的图像大小调整类

时间:2013-05-18 15:10:35

标签: php wordpress class

我已经创建了一个基于

调整WordPress图像大小的功能

http://www.hashbangcode.com/blog/create-images-thumbnails-and-cache-them-php-287.html

但是我收到了这个错误:

Fatal error: Cannot redeclare class image_resize

但是我还没有把这个课打成电话。

这是我的功能

function resize_image($thumb_id){
        //check for thumbnail cache if not then create it
    $attachment = wp_get_attachment_image_src($thumb_id, 'large');
    $image_url = pathinfo($attachment[0]);

    if (file_exists(get_template_directory().'/images/thumbs/' . $image_url['basename'])) {
      // 2592000 = 30 days
      if ( time() - filemtime(get_template_directory().'/images/thumbs/'.$image_url['basename']) > 2592000 ) {
        unlink(get_template_directory().'/images/thumbs/'.$image_url['basename']);
      }
    }
    if (!file_exists(get_template_directory().'/images/thumbs/' . $image_url['basename'])) {
      include(get_template_directory().'/inc/image_resize.php');
      // if cache file does not exist then create it.
      $originalImage = new imageResize($attachment[0]);
      $originalImage->size_width(120);
      $originalImage->save(get_template_directory().'/images/thumbs/'.$image_url['basename']);
    }
}
请告诉我它有什么不对吗?

1 个答案:

答案 0 :(得分:2)

您要包含之前已包含的image_resize.php。因此,您尝试执行ImageResize类声明两次,从而得到错误。

include替换为include once并花一些时间阅读其文档及其含义。