2017-10-04 10 views
1

사용자가 내 웹 사이트에 제품을 추가 할 수 있도록 CodeIgniter에 대한 웹 사이트를 만들고 있습니다. 그림이 축소판을 만들 수 있도록 크기 조정 기능을 만들었습니다. 이제이 축소판 그림의 너비가 168px 및 높이 : 112px보다 큰 경우에만 크기가 조정됩니다. 사진이 그보다 작 으면 사진의 크기가 조절되지 않습니다. 업로드 한 모든 사진의 가로 및 세로 크기는 각각 168px 및 112px 인 미리보기 이미지를 원합니다.Codeigniter 그림 크기 조정이 제대로 작동하지 않습니다.

썸네일 이미지 코드 :

$dataThumb = $this->upload->data(); 
     $configThumb['image_library'] = 'gd2'; 
     $configThumb['source_image'] = './upload/'.$dataThumb["raw_name"].$dataThumb['file_ext']; 
     $configThumb['new_image'] = './upload/'.'thumb_'.$dataThumb["raw_name"].$dataThumb['file_ext']; 
     $configThumb['create_thumb'] = TRUE; 
     $configThumb['maintain_ratio'] = TRUE; 
     $configThumb['width'] = 168; 
     $configThumb['height'] = 112; 

내 전체 업로드 제품 코드 :

public function upload() { 
     $this->load->library('upload'); 
     $this->load->library('image_lib'); 

     $config['upload_path'] = './upload/'; 
     $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg'; 
     $config['max_size'] = '0'; 
     $config['max_width'] = '0'; 
     $config['max_height'] = '0'; 
     $config['encrypt_name']= true; 
     $this->upload->initialize($config); 


     if(!$this->upload->do_upload('userfile')){ 
      $error = array('error'=>$this->upload->display_errors()); 
      $this->load->view('product_form', $error); 
     }else{ 
      //Main image 
      $data = $this->upload->data(); 
      $config['image_library'] = 'gd2'; 
      $config['source_image'] = './upload/'.$data["raw_name"].$data['file_ext']; 
      $config['new_image'] = './upload/'.'new_'.$data["raw_name"].$data['file_ext']; 
      $config['create_thumb'] = FALSE; 
      $config['maintain_ratio'] = FALSE; 
      $config['width'] = 547; 
      $config['height'] = 430; 

      //Thumb image 
      $dataThumb = $this->upload->data(); 
      $configThumb['image_library'] = 'gd2'; 
      $configThumb['source_image'] = './upload/'.$dataThumb["raw_name"].$dataThumb['file_ext']; 
      $configThumb['new_image'] = './upload/'.'thumb_'.$dataThumb["raw_name"].$dataThumb['file_ext']; 
      $configThumb['create_thumb'] = TRUE; 
      $configThumb['maintain_ratio'] = TRUE; 
      $configThumb['width'] = 168; 
      $configThumb['height'] = 112; 

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

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

      $this-> db-> insert('products', array(
       'user_id' => $_SESSION['user_id'], 
       'product_foto' => 'new_'.$data["raw_name"].$data['file_ext'], 
       'product_foto_thumb' => 'thumb_'.$dataThumb["raw_name"].$dataThumb['file_ext'], 
       'product_naam' => $this->input->post('product_naam'), 
       'product_beschrijving' => $this->input->post('product_beschrijving'), 
       'ophaal_plaats' => $this->input->post('ophaal_plaats'), 
       'category_id' => !empty($this->input->post('category_id')) ? $this->input->post('category_id') : 0, 
       'date_created' => date('Y-m-d'), 
       'date_updated' => date('Y-m-d') 
       )); 
      $data['img'] = base_url(). 
      '/upload/new_'.$data["raw_name"].$data['file_ext']; 
      $dataThumb['img'] = base_url(). 
      '/upload/thumb_'.$dataThumb["raw_name"].$dataThumb['file_ext']; 

      header('location:https://kadokado-ferran10.c9users.io/Product/'); 

     } 
    } 
+0

(당신의 치수보다 큰) 당신은 무엇을 의미합니까했다 : 아래 은 결과입니까? – JohnDoe122

+0

문제는 내가 업로드 한 작은 그림이 168 너비와 112 높이로 크기가 조정되지 않는다는 것입니다. – JohnDoe122

+0

디버깅을 설정했기 때문에'system/libraries/Image_lib.php'를 통해 볼 수 있고 그 마지막 내용 $ width 및 $ height는?로 설정됩니다. (또는 관심있는 지점에'log_message' 명령을 넣으십시오.) – ourmandave

답변

0
$config['maintain_ratio'] = TRUE; 

위의 코드 크기를 조정하면 원래의 가로 세로 비율을 유지할지 여부를 지정합니다. true로 설정하면 이미지 해상도가 변경됩니다.

$config['maintain_ratio'] = FALSE; //DO this 

이렇게하면 해상도가 고정됩니다. 이 테스트를 거쳤습니다. 원본 이미지가 모두 512 X 512 (당신의 치수보다 작은) 100 X 100 enter image description here

+0

내 엄지 손톱 그림에서 내 코드를 보렴 – JohnDoe122

+0

정확히 무엇이 문제인지 자세히 알 수 있겠습니까? –

+0

내 축소판 그림 코드에서 볼 수 있듯이이 그림의 크기는 $ configThumb [ 'width'] = 168; $ configThumb [ 'height'] = 112. 좋아, 그래서 그림이 그 크기보다 작더라도 모든 그림을 그 그림 크기로 크기를 바꿉니다. 그래서 지금은 그림이 그 크기보다 크면 크기가 조정되지만 그 크기보다 작 으면 크기가 조정되지 않습니다. 내가 무슨 말하는지 이해 하겠니? – JohnDoe122