使用codeigniter的图像裁剪没有GD库-GD2


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非常适合准确、相关的错误消息)。以下是我将采取的步骤来解决它:

  1. var_dump(file_exists($config['source_image'])查看PHP是否找到该文件。我会被这里的"真实"回应所震惊
  2. 如果文件系统区分大小写,请确保这不是问题所在
  3. 检查include路径(如果CI走到这一步,我认为常规include可以正常工作…)
  4. 更多的是反步骤,但不要使用$_SERVER['DOCUMENT_ROOT'],正如一位评论者所建议的那样。FC_PATH(或其他CI定义的常量)应该为您提供所需的基本路径

狩猎快乐。