2012-07-16 8 views
2

하이를 만들려면 image_lib 이미지와 이미지의 크기를 조정할 수있는 CI 문서에 따라 그리고 우리가 여기는 이미지 크기를 조정하고 축소판을

create_thumb FALSE TRUE/FALSE (boolean) Tells the image processing function to create a thumb. R 
thumb_marker _thumb None Specifies the thumbnail indicator. It will be inserted just before the file extension, so mypic.jpg would become mypic_thumb.jpg R 

해당 이미지에서 추가 축소판을 만들 수 있습니다 제안 옵션이 내 코드가되어 있습니다 CodeIgniter의

 $config_manip = array(
      'image_library' => 'gd2', 
      'source_image' => "./uploads/avatar/tmp/{$this->input->post('new_val')}", 
      'new_image'  => "./uploads/avatar/{$this->input->post('new_val')}", 
      'maintain_ratio'=> TRUE , 
      'create_thumb' => TRUE , 
      'thumb_marker' => '_thumb' , 
      'width'   => 150, 
      'height'  => 150 
     ); 

     $this->load->library('image_lib', $config_manip); 
     $this->image_lib->resize(); 
이 코드는 내 이미지 크기를 조정하고 또한 썸네일을 생성하지만 난 단지 지정된 크기와 _tump 접미사 하나 개의 이미지를 얻을 가정 것이다

내가했습니다 루게릭 병 o를 수동으로 두 번째 이미지를 만들려면이 코드를 추가하려하지만 여전히 작동하지 않습니다와 나는 하나 개의 이미지 만

  $this->image_lib->clear(); 

$config_manip['new_image'] = 
"./uploads/avatar/thumbnail_{$this->input->post('new_val')}"; 

      $config_manip['width']  = 30 ; 
      $config_manip['height'] = 30 ; 
      $this->load->library('image_lib', $config_manip); 
      $this->image_lib->resize(); 
+0

원하는 결과가 있습니까? 원래 크기를 수정하고 30x30 크기의 이미지를 만들겠습니까? –

+0

실제로 내 원본 이미지는 보안상의 이유로 임시 폴더에 있습니다. 내 아바타 폴더에있는 크기 조정 된 파일과 미리보기 이미지를 만들고 싶습니다. – max

+0

'create_thumb'을 제거하면이 두 부분의 코드가 트릭을 수행합니다. ''{} ''안에 함수를 실행할 수 있다는 것을 몰랐습니까? –

답변

17

경로가 코드에서 문제가 보인다 얻을. 나는 그것을 수정하고 스스로 테스트했다.

public function do_resize() 
{ 
    $filename = $this->input->post('new_val'); 
    $source_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/tmp/' . $filename; 
    $target_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/'; 
    $config_manip = array(
     'image_library' => 'gd2', 
     'source_image' => $source_path, 
     'new_image' => $target_path, 
     'maintain_ratio' => TRUE, 
     'create_thumb' => TRUE, 
     'thumb_marker' => '_thumb', 
     'width' => 150, 
     'height' => 150 
    ); 
    $this->load->library('image_lib', $config_manip); 
    if (!$this->image_lib->resize()) { 
     echo $this->image_lib->display_errors(); 
    } 
    // clear // 
    $this->image_lib->clear(); 
} 

희망이 도움이 될 것입니다. 감사!!

+0

고맙지 만 $ _SERVER [ 'DOCUMENT_ROOT']를 사용할 수 없습니다. 메신저 로컬에서 응용 프로그램을 실행하고 이것이 내가 얻는 주소입니다 : C : /wamp/www/uploads/avatar/tmp/500419bfe5d98.jpg 잘못 C :/wamp/www/mywebsitefolder/uploads /이어야합니다. .. – max

+0

@max, 당신의 설치 가상 호스트 및 루트 디렉토리로 websitefolder를 만들 경우 localhost 에서뿐만 아니라 작동합니다. 어떤 설정도없이 웹 서버에서 100 % 작동합니다. 현재 www가 루트 디렉토리이므로 프로젝트 폴더가 숨겨져 있습니다. 수동으로 프로젝트 폴더 이름을 추가하거나 솔루션 인 가상 호스트를 설정하십시오. 감사!! –

+0

내 엄지 손가락의 너비와 높이가 맞았지만 source_image의 크기가 조정되지 않았습니다 ... 나는 두 가지 일이 발생할 것으로 예상했습니다. 1) 소스 이미지의 크기가 조정되고 2)'_thumb' 토큰이있는 축소판이 생성됩니다. .. ... ...하지만 너비/높이 값의 2 세트가 필요합니다 ... – dsdsdsdsd

2

간단한 방법으로 미리보기 이미지를 만들 수 있습니다. 당신이 resize() 방법을 사용하여 둘 이상의 이미지를 만들려면

function _create_thumbnail($fileName, $width, $height) 
{ 
    $this->load->library('image_lib'); 
    $config['image_library'] = 'gd2'; 
    $config['source_image'] = $_SERVER['DOCUMENT_ROOT']. $fileName;  
    $config['create_thumb'] = TRUE; 
    $config['maintain_ratio'] = TRUE; 
    $config['width']   = $width; 
    $config['height']   = $height; 
    $config['new_image']  = $_SERVER['DOCUMENT_ROOT']. $fileName;    
    $this->image_lib->initialize($config); 
    if (! $this->image_lib->resize()) { 
     echo $this->image_lib->display_errors(); 
    }   
} 
+0

감사합니다, 이것은 나를 위해 완벽 ans :) –

2

귀하의 코드는 괜찮 위해 그것을 해결하지만 당신은 작은 변화 할 필요가있다.

$this->load->library('image_lib'); 
$this->image_lib->initialize($config_manip); 
관련 문제