繁体   English   中英

使用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是否找到该文件。我对这里的“ true”响应感到震惊。
  2. 如果文件系统区分大小写,请确保这不是问题
  3. 检查include路径(如果CI到此为止,我认为常规的include可以正常工作...)
  4. 更多的是反步骤,但不要使用$_SERVER['DOCUMENT_ROOT'] ,如评论者所建议的那样。 FC_PATH (或其他CI定义的常量)应该为您提供所需的基本路径。

狩猎愉快。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM