【发布时间】:2012-02-01 17:38:10
【问题描述】:
我目前正在为一个网站制作媒体库,其中一个功能是用户可以创建他们上传的图像的裁剪版本。
但是我的问题是,当我尝试裁剪图像时,出现以下错误,
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 并不意味着它可以处理所有常见的文件格式。
-
您是否尝试过文档根目录的绝对路径?试试
$_SERVER['DOCUMENT_ROOT'] . 'rest/of/path/to/file' -
GD_INFO 会告诉它支持什么吗?我以前在这台机器上裁剪过 PNG。
-
试过 DOCUMENT_ROOT 没有成功
标签: php codeigniter codeigniter-2 crop gd2