代码对我来说就像一个魅力。但我现在已经将文件从一台服务器转移到另一台服务器,现在它无法正常工作。图像正在上传(原始) - > image.jpg
,但调整thumb_image.jpg
和featured_image.jpg
后的其他两张图片均未上传。我不知道问题是什么。
我浏览了错误日志,我看到了这3行代码
ERROR - 2013-09-08 17:38:26 --> PNG images are not supported.
ERROR - 2013-09-08 17:38:26 --> The path to the image is not correct.
ERROR - 2013-09-08 17:38:26 --> Your server does not support the GD function required to process this type of image.
我不明白图像路径的问题是什么,为什么它不支持PNG图像,因为它工作得很好。
调整大小代码
public function resizeIMG($imagePath, $filename){
$this->load->library('image_lib');
$configThumb['image_library'] = 'gd2';
$configThumb['source_image'] = $imagePath;
$configThumb['create_thumb'] = FALSE;
$configThumb['new_image'] = 'thumb_'.$filename;
$configThumb['maintain_ratio'] = TRUE;
$configThumb['width'] = 260;
$configThumb['height'] = 215;
$configFeatured['image_library'] = 'gd2';
$configFeatured['source_image'] = $imagePath;
$configFeatured['create_thumb'] = FALSE;
$configFeatured['new_image'] = 'featured_'.$filename;
$configFeatured['maintain_ratio'] = TRUE;
$configFeatured['width'] = 800;
$configFeatured['height'] = 500;
$configCropFeatured['image_library'] = 'gd2';
$configCropFeatured['source_image'] = './uploads/featured_'.$filename;
$configCropFeatured['x_axis'] = '0';
$configCropFeatured['y_axis'] = '0';
$configCropFeatured['create_thumb'] = FALSE;
$configCropFeatured['new_image'] = 'featured_'.$filename;
$configCropFeatured['maintain_ratio'] = FALSE;
$configCropFeatured['width'] = 720;
$configCropFeatured['height'] = 250;
$this->image_lib->initialize($configThumb);
$this->image_lib->resize();
$this->image_lib->initialize($configFeatured);
$this->image_lib->resize();
$this->image_lib->initialize($configCropFeatured);
$this->image_lib->crop();
}
答案 0 :(得分:2)
日志说Your server does not support the GD function required to process this type of image.
表示您的服务器主机未启用GD库(或者可能因任何原因禁用您正在使用的功能)
您需要联系您的虚拟主机,了解他们是否可以启用GD。如果没有,您将需要转换您的应用程序以使用不同的库。您可以通过在PHP脚本中运行phpinfo()
来找出可用的库。如果GD被禁用,则最有可能的是,ImageMagick被打开 - 您可以查看该页面,一旦您了解了基本功能,您就可以将应用程序转换为使用ImageMagick。请确保ImageMagick(或imagick
)在phpinfo()的某处。如果没有,你可能最好要求你的主机启用其中一个插件。