2012-02-01 107 views
0

我正在为网站的媒体库目前工作,其中一个功能是用户可以创建他们上传的图像的裁剪版本。图像裁剪与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。

+0

GD2可能已安装,但它是否支持PNG编译?仅仅因为GD在那里并不意味着它可以处理所有通常的文件格式。 – 2012-02-01 17:40:24

+0

您是否尝试过从文档根目录的绝对路径?试试'$ _SERVER ['DOCUMENT_ROOT']。 'rest/of/path/to/file'' – 2012-02-01 17:41:12

+0

GD_INFO会告诉它支持什么?我在这台机器上预先裁剪过PNG。 – Udders 2012-02-01 17:41:49

回答

0

这很可能只是一个文件路径问题(CI对于准确的相关错误消息非常好)。下面是我将采取的步骤来解决它:

  1. var_dump(file_exists($config['source_image'])看看PHP是否找到该文件。这里我会被一个“真实”的回应震惊。
  2. 如果文件系统是大小写敏感的,确保这不是问题
  3. 检查包括路径(我假设定期包括如果CI得到这一步工作正常...)
  4. 更多的反步,但请注意,不要使用$_SERVER['DOCUMENT_ROOT']FC_PATH(或其他CI定义的常量)应该为您提供所需的基本路径。

快乐的狩猎。

+0

file_exists返回TRUE,还有其他想法吗? – Udders 2012-02-02 10:37:20

+0

真是莫名其妙。也许可以在相关的图像处理函数中加入一些逐步的调试输出来找出它到达错误状态的位置? – landons 2012-02-02 23:05:30

+0

想到了,我提交表单到'controller/view',但'$ this-> data ['image']'是从URI段构建的,所以需要将表单提交给'current_url()' – Udders 2012-02-03 09:43:49