我目前正在为网站制作媒体库,其中一项功能是用户可以创建他们上传的图片的裁剪版本。
我的问题是,当我尝试裁剪图像时,我收到以下错误,
The path to the image is not correct.
这是我的代码,
$config['image_library'] = 'gd2';
$config['source_image'] = "/media/images/products/".$this->data['image'];
//die($config['source_image']);
$config['maintain_ratio'] = FALSE;
$config['x_axis'] = $this->input->post('x');
$config['y_axis'] = $this->input->post('y');
$config['width'] = $this->input->post('w');
$config['height'] = $this->input->post('h');
$config['dynamic_output'] = FALSE;
$config['create_thumb'] = TRUE;
$this->load->library('image_lib', $config);
if(!$this->image_lib->crop()) {
if($this->input->post('isAjax') == "1") {
echo json_encode($this->image_lib->display_errors());
} else {
$this->data['image_error'] = $this->image_lib->display_errors();
$this->template->build('/admin/media/crop', $this->data);
}
} else {
$filename = base_url()."media/images/products/".$this->data['image'];
$extension_pos = strrpos($filename, '.'); // find position of the last dot, so where the extension starts
$thumb = substr($filename, 0, $extension_pos) . '_thumb' . substr($filename, $extension_pos);
if($this->input->post('isAjax') == 1) {
echo json_encode($success = array('message' => 'Image Cropped'));
} else {
$this->data['success'] = "Image Cropped";
$this->template->build('/admin/media/crop', $this->data);
}
}
所以我虽然将$config['source_image']
更改为以下内容,
$config['source_image'] = "./media/images/products/".$this->data['image'];
然而,只留下这条消息,
Your server does not support the GD function required to process this type of image.
我做了一些根本错误的事吗?我只是尝试裁剪一个简单的.png,而且该文件肯定存在于我的服务器上,而且我最肯定安装了GD2。
答案 0 :(得分:0)
很可能只是一个文件路径问题(CI对于准确的相关错误消息非常好)。以下是我将采取的解决方法:
var_dump(file_exists($config['source_image'])
查看PHP是否找到该文件。我会对这里的“真实”回应感到震惊。$_SERVER['DOCUMENT_ROOT']
。 FC_PATH
(或其他CI定义的常量)应该为您提供所需的基本路径。快乐狩猎。