我目前正在为一个网站开发媒体库,其中一个功能是用户可以创建他们上传的图像的裁剪版本。
但是,我的问题是,当我尝试裁剪图像时,出现以下错误,
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。