2011-01-24 4 views
0

이미지를 자르면 완전히 검은 색으로 변합니까 ?? 왜??코드 니터 - 잘린 이미지가 검은 색이됩니다.

$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'; $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg'; 

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


    if(!$this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); $this->load->view('submit', $error); } else { $data['upload_data'] = array('upload_data' => $this->upload->data()); $file_name 
    = $this->upload->file_name; 

     list($image_width, $image_height) = getimagesize($_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'.$file_name); 

     // create small size $config['image_library'] = 'GD2'; $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'.$file_name; $config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name; $config['maintain_ratio'] = TRUE; $config['width'] = 181; $config['height'] = 115; $config['master_dim'] = 'width'; 

     $this->load->library('image_lib'); $this->image_lib->initialize($config); 

     if($image_width >= $config['width'] AND $image_height >= $config['height']) { 
      if (!$this->image_lib->resize()) 
      { 
      echo $this->image_lib->display_errors(); 
      } else { 
      if(file_exists($_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name)) 

      { 
       list($image_width, $image_height) = getimagesize($_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name); 
       if($image_height > '115') 
       { 
       $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name; 
       $y_axis = $image_height - 115; 
       $config['y_axis'] = $y_axis; 
       $config['x_axis'] = 181; 
       $this->image_lib->initialize($config); 
       if (!$this->image_lib->crop()) 
        { 
         echo $this->image_lib->display_errors(); 
        } else { 
         echo "cropped";  
       } 
      } 
      } } } 

답변

1

저는 CI가 표준 PHP GD 모듈을 사용한다고 생각합니다. 이전에 사용중인 이미지가 약간 손상 되었다면 여전히 정상적으로 표시되지만 일단 크기를 조정하면 블랙 박스가 생기는 것을 발견했습니다.

다른 이미지를 사용해 보셨습니까? 다른 유형의 이미지 (png/jpg/etc)?

+0

예 나는 여전히 동일한 결과를 보았습니다. (image-magick을 사용하려고했으나 읽어야 할 내용을 읽거나 설치해야합니까? – wonderwoman

+0

예, image-magick 라이브러리는 설치해야하지만 매우 간단합니다 (도움이되는 튜토리얼이 많이 있습니다). 사용하기가 더 쉽습니다. 시도해볼 것을 권합니다. –

+0

실제로 GD2에서 작동합니다. 위와 아래 모두에서 자르기가 가능한지 궁금합니다. – wonderwoman

관련 문제