我有一个网站可以获取用户上传的图像,并制作三份副本 - 一个“完整”副本打印(缩小到 1500x1125),一个“网络”副本在线显示(尚未编码),最后是缩略图。
所以这里的代码 - _imageformat() 从 CI 的上传类传递参数(我已经确认是正确的):
function _imageformat($fullpath, $shortpath, $width, $height)
{ // 我们现在格式化图像。
// 首先,我们检查它是横向还是纵向 if ($width >= $height) // 它是横向(或正方形) { // 现在创建完整的打印图像 $fullimage = $this->_resize('l' , $fullpath, $shortpath, $width, $height); } else // 这是纵向的 { // 现在创建完整的打印图像 $fullimage = $this->_resize('p', $fullpath, $shortpath, $width, $height); }
}
function _resize($type, $fullpath, $shortpath, $width, $height) { // 设置默认的图像处理配置选项 $config['image_library'] = 'gd2'; $config['source_image'] = $fullpath; $config['maintain_ratio'] = 真;
// Shave the '.jpg' from the end to append some nice suffixes we'll use
$newimage = substr($fullpath, 0, -4).'_full'.".jpg";
$config['new_image'] = $newimage;
if ($type == 'l') // If it's landscape
{
$config['width'] = 1500;
$config['height'] = 1125;
}
else if ($type == 'p') // If it's portrait
{
$config['width'] = 1125;
$config['height'] = 1500;
}
// Load the image library with the specified parameters, and resize the image!
$this->load->library('image_lib', $config);
$this->image_lib->resize();
// Create a thumbnail from the full image
$config['source_image'] = $newimage;
$config['new_image'] = substr($fullpath, 0, -9)."_thumb".".jpg";
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 150;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
return $newimage;
}
应该发生什么:在我的上传文件夹中,有三张图片 - 原始上传的文件(我们称之为 image.jpg)、调整大小的文件(命名为 image_full.jpg)和缩略图(命名为 image_thumb.jpg)。
会发生什么:在我的上传文件夹中,只有两张图像 - 原始上传文件 (image.jpg) 和调整大小的文件 (image_full.jpg) 。从未创建任何缩略图。
然而,有趣的是,** 如果我首先放置创建缩略图的代码,它会生成缩略图,但 ** 不会生成 _full(调整大小的)图像。
所以在我看来,它永远不会运行$this->image_lib->resize()
两次。为什么不?是我犯了一些业余错误,还是我错过了一些明显的东西?!:P
谢谢!
杰克
编辑:我应该指出,是的,我知道我要加载image_lib
库两次。我知道这是向它传递新参数的唯一方法。在调整完整图像的大小后,我还尝试调用$this->_thumbnail()
which 在此处再次加载库。但还是出现了同样的问题。
编辑 2:我也尝试过使用$this->image_lib->clear()
- 仍然没有运气。