CodeIgniter图像处理JPG错误

时间:2014-02-25 11:47:37

标签: php codeigniter jpeg image-manipulation gd2

我已经使用CodeIgniter为我的个人网站编写了一个系统,并使用GD2库根据我的需要操作图像。它在localhost和我用于测试的免费托管时工作得很好。但是现在我正在使用来自不同提供商的付费主机,它不适用于jpg文件。它显示了破碎的图标图标。但是对于PNG文件可以正常工作。我试过显示操作错误但没有显示任何内容。

这是我的媒体控制器,它操纵图像;

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Media extends CI_Controller
{

function sandbox($imageName , $width)
  {

      if(!is_file('uploads/sandbox/'.$width.'-'.$imageName)) {
         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/original/'.$imageName;
         $config['new_image'] = 'uploads/sandbox/'.$width.'-'.$imageName;
         $config['dynamic_output'] = FALSE;
         $config['maintain_ratio'] = TRUE;
         $config['master_dim'] = 'width';
         $config['width'] = $width;
         $config['height'] = $width;

         $this->image_lib->initialize($config);
         return $this->image_lib->resize();
    }    else {
        return true;
    }

  }

  public function covers($imageName)
  {

     if($this->sandbox($imageName, 920)) {

         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/sandbox/'.'920-'.$imageName;
         $config['dynamic_output'] = TRUE;
         $config['maintain_ratio'] = FALSE;
         $config['width'] = 920;
         $config['height'] = 450;

         $this->image_lib->initialize($config);
         $this->image_lib->crop();

     }


  }

  public function images($imageName)
  {

     if($this->sandbox($imageName, 440)) {

         $config['image_library'] = 'gd2';
         $config['source_image'] = 'uploads/sandbox/'.'440-'.$imageName;
         $config['dynamic_output'] = TRUE;
         $config['maintain_ratio'] = FALSE;
         $config['width'] = 440;
         $config['height'] = 300;

         $this->image_lib->initialize($config);
         if(!$this->image_lib->crop()){
            echo $this->image_lib->display_errors();
         }

     }

  }

  public function facebook($imageName)
  {

     $config['image_library'] = 'gd2';
     $config['source_image'] = 'uploads/original/'.$imageName;
     $config['dynamic_output'] = TRUE;
     $config['maintain_ratio'] = FALSE;
     $config['width'] = 256;
     $config['height'] = 256;

     $this->image_lib->initialize($config);
     echo $this->image_lib->resize();

  }

}

1 个答案:

答案 0 :(得分:0)

安装GD2时必须启用Jpeg; http://php.net/manual/en/image.installation.php