我正在为网站的媒体库目前工作,其中一个功能是用户可以创建他们上传的图像的裁剪版本。图像裁剪与codeigniter否GD库 - GD2已安装
但是我的问题是这样的,当我尝试裁剪图像,我得到以下错误,
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。
GD2可能已安装,但它是否支持PNG编译?仅仅因为GD在那里并不意味着它可以处理所有通常的文件格式。 – 2012-02-01 17:40:24
您是否尝试过从文档根目录的绝对路径?试试'$ _SERVER ['DOCUMENT_ROOT']。 'rest/of/path/to/file'' – 2012-02-01 17:41:12
GD_INFO会告诉它支持什么?我在这台机器上预先裁剪过PNG。 – Udders 2012-02-01 17:41:49