2016-04-29 19 views
0

以下は1000px幅以下の画像を試したときのコードですが、1000px以上では動作しませんでした。Codeigniter Image 1000pxの幅以上でResize()が動作しないImage

$img_array = array(); 
    $img_array['image_library'] = 'gd2'; 
    $img_array['maintain_ratio'] = TRUE; 
    $img_array['create_thumb'] = TRUE; 
    $thumb_name = $img_array['new_image'] = './public/image/thumb/' . $file; 
    //you need this setting to tell the image lib which image to process 
    $img_array['source_image'] = $path; 
    $img_array['width'] = 180; 
    $img_array['height'] = 250; 


    $this->image_lib->clear(); // added this line 
    $this->image_lib->initialize($img_array); // added this line 
    if (!$this->image_lib->resize()) 
    { 
     echo $this->image_lib->display_errors(); exit; 
    } 
    return $thumb_name; 
    } 
+0

コードを試すコントローラで呼び出し、あなたのために働いているかどうか私に教えてください。 –

+0

ファイルアップロードが正常に動作していますが、サイズを変更するとエラーが発生します。「画像へのパスが正しくありません。サーバーはこのタイプの画像を処理するために必要なGD機能をサポートしていません。 –

+0

サーバのGDライブラリが有効かどうかを調べる\ –

答えて

0

モデルは、モデル

class Image_model extends CI_Model { 
public function __construct() { 
    parent::__construct(); 
    $this->load->helper('url'); 
    $this->load->library('upload'); 
    $this->load->library('image_lib'); 
} 
public function do_resize($filename) 
{ 

    $source_path = 'uploads/' . $filename; 
    //create a directory thumb in uploads set as target path 
    $target_path = 'uploads/thumb/thumb_'.$filename; 

    $config_manip = array(

     'image_library' => 'gd2', 
     'source_image' => $source_path, 
     'new_image' => $target_path, 
     'maintain_ratio' => TRUE, 
     'width' => 180, 
     'height' => 250 
    ); 
    $this->image_lib->initialize($config_manip); 
    $this->load->library('image_lib', $config_manip); 


    if (!$this->image_lib->resize()) { 
     echo $this->image_lib->display_errors(); 
     die(); 
    } 
    // clear // 
    //$this->image_lib->clear(); 
} 

public function img_upload() 
{ 
    $config = array(
     'upload_path' => "uploads", 
     'allowed_types' => "*", 
     'overwrite' => TRUE, 
     'max_size' => "5048000", // Can be set to particular file size , here it is 2 MB(2048 Kb) 
     'max_height' => "3000", 
     'max_width' => "3000" 
    ); 
    $this->upload->initialize($config); 
    $this->load->library('upload', $config); 

    if($this->upload->do_upload()) { 
     $response = array('upload_data' => $this->upload->data()); 
     //here calling the function do_resize 
     $this->do_resize($response['upload_data']['file_name']); 
     //return $response; 
    } 
    /*else{ 
     $error    = array('error'=>$this->upload->display_errors()); 
     //print_r($error);die(); 

    }*/ 
    } 
} 

にこのコードを置くフォルダにImage_modelとしてモデル名を作成し、このような機能コントローラは、ここで

class your_controller extends CI_Controller { 

function __construct(){ 
    parent::__construct(); 
    $this->load->model('image_model'); 
} 
    // here the function to save name in database 
public function add() { 
     $data      = array(); 
     $config      = array();  
     if(isset($_FILES)){ 
      $config    = $this->image_model->img_upload(); 
      $file_data    = $this->upload->data(); 
      $data['image']   = $file_data['file_name']; 
     } 
      else 
      $data['image']   = "no-image"; 
     // here the function in your model to save the name of image in your database      
     $last_id    =  $this->your_model->save($data); 
     $this->load->view('your_view'); 
    } 
+0

ファイルのアップロードはうまくいきましたが、画像へのパスが正しくありません。サーバーはこのタイプの画像を処理するために必要なGD機能をサポートしていません。 –

関連する問題