我创建了一个基于
调整WordPress图像大小的函数http://www.hashbangcode.com/blog/create -图片缩略图-和-缓存- 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']);
}
}
请告诉我有什么问题??
您包含了之前已经包含的image_resize.php
。因此,您尝试执行两次ImageResize
类声明,从而得到错误。
用include代替你的include
一次,花点时间阅读它的文档和它的含义