[英]image cropping with codeigniter no GD library - GD2 is intalled
目前,我正在為網站制作媒體庫,其中一項功能是用戶可以創建自己上傳的圖片的裁剪版本。
但是我的問題是,當我嘗試裁剪圖像時,出現以下錯誤,
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。
這很可能只是文件路徑問題(CI非常適合准確,相關的錯誤消息)。 以下是我要解決的步驟:
var_dump(file_exists($config['source_image'])
來查看PHP是否找到該文件。我對這里的“ true”響應感到震驚。 $_SERVER['DOCUMENT_ROOT']
,如評論者所建議的那樣。 FC_PATH
(或其他CI定義的常量)應該為您提供所需的基本路徑。 狩獵愉快。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.