我正在爲網站的媒體庫目前工作,其中一個功能是用戶可以創建他們上傳的圖像的裁剪版本。圖像裁剪與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