图像裁剪与codeigniter没有GD库 - GD2是安装的 [英] image cropping with codeigniter no GD library - GD2 is intalled

查看:448
本文介绍了图像裁剪与codeigniter没有GD库 - GD2是安装的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在处理网站的媒体库,其中一个功能是用户可以创建他们上传的图片的裁剪版本。

I am working on media library for a website at the moment, and one of the features is that user can create a cropped version of an image that they upload.

我的问题是这样的,当我尝试和裁剪图像,我得到以下错误,

My problem however is this, when I try and crop the image, I get the following error,

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'] 到以下

So I though I would change $config['source_image'] to the following,

$config['source_image'] = "./media/images/products/".$this->data['image'];

但是这只是留下这个讯息,

however that just leaves with this message,

Your server does not support the GD function required to process this type of image.

我做错根本错了吗?我只是想修剪一个简单的.png,文件肯定存在我的服务器,我最确定的GD2安装。

Am I doing something fundamentally wrong? I am only trying to crop a simple .png, and the file certainly exists on my server, and I most definatly have GD2 installed.

推荐答案

这很可能只是一个文件路径问题(CI是相当好的准确,相关的错误消息)。以下是解决问题的步骤:

The is most likely just a file path issue (CI is pretty good about accurate, relevant error messages). Here are the steps I would take to resolve it:


  1. var_dump(file_exists($ config ['source_image'] )查看PHP是否找到了这个文件,我会对这里的true响应感到震惊。

  2. 如果文件系统区分大小写,这不是问题

  3. 检查包含路径(如果CI得到这个值,我认为正常工作正常)

  4. 反义词,但不要使用 $ _ SERVER ['DOCUMENT_ROOT'] ,作为注释者建议。 FC_PATH 或其他CI定义的常数)应该为您提供所需的基本路径。

  1. var_dump(file_exists($config['source_image']) to see if PHP finds the file. I'd be shocked by a "true" response here.
  2. If the filesystem is case-sensitive, make sure that's not the problem
  3. Check the include path (I assume regular includes are working fine if CI gets this far...)
  4. More of an anti-step, but DON'T use $_SERVER['DOCUMENT_ROOT'], as a commenter suggests. FC_PATH (or other CI-defined constants) should get you the base path you need.

快乐狩猎。

这篇关于图像裁剪与codeigniter没有GD库 - GD2是安装的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆