2017-11-09 6 views
0

誰かが私を助けることができますか?私は私の画像のアップロードをトリミングし、私のプロフィールの写真を変更したいが、私はまだ画像が動作していない、プロフィールの画像は変更されていない、ログアウトする必要がありますし、画像が変更された、私は理解しています。これは私のコントローラです。Image Codeigniterでクロッピングする

private $pk = 'nim'; 
private $table = 'mahasiswa'; 

public function update() 
    { 
     $nim = $this->session->userdata('nim'); 
     if($_POST) { 
      $file = $this->upload(); 
      if ($this->m_data->update($this->pk, $nim, $this->table, $this->field_data($file['data']))) { 

      redirect('Mahasiswa/Profil'); 
    } 
} else { 
    redirect('Mahasiswa/Formubah'); 
} 
} 

private function field_data($file = '') 
{ 

    $data['username'] = $this->input->post('username'); 
    $data['password'] = $this->input->post('password'); 
    if ($file != '') { 
     $data['foto'] = $file['file_name']; 
    } 

    return $data; 

} 

public function upload() 
{ 
    $config['upload_path'] = './assets/image/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = 0; 
    $config['remove_spaces'] = TRUE; 

    $this->load->library('upload', $config); 

    if (! $this->upload->do_upload('foto')){ 

     return[ 
      'data' => $this->upload->display_errors(), 
     ]; 

    } else { 

     $data = $this->upload->data(); 
     $resize['image_library'] = 'gd2'; 
     $resize['x_axis'] = 50; 
     $resize['y_axis'] = 50; 
     $resize['width'] = $img['config']['foto']['width']; 

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

     $this->image_lib->crop(); 

     return [ 
     'data' => $this->upload->data(), 
     ]; 



    } 
} 

私はコントローラーで十分でした。私は言うことを忘れて、私はこのショーの私の写真を使用します。 <?php echo base_url('assets/image/').$this->session->userdata('foto');?>

+0

あなたは例のリンクにしたい場合はhttp://kennykee.com/138/codeigniter-resize-and-crop-image-to-fit-container-div-example/ –

答えて

0

ライブラリを正しく実装していません。ライブラリのロードを忘れ、パスが指定されていない。

$image_data = $this->upload->data(); 
$config['image_library'] = 'imagemagick'; 
$config['library_path'] = 'C:ImageMagick-7.0.1-3-portable-Q16-x86';//your library 
$config['source_image'] = $image_data['full_path']; //get original image 
$config['x_axis'] = 50; 
$config['y_axis'] = 50; 
$this->load->library('image_lib', $config); 
if (!$this->image_lib->crop()) { 
    $this->handle_error($this->image_lib->display_errors()); 
} 
関連する問題