2011-08-15 3 views
2

다음 코드를 사용하고 있지만 축소판이 만들어지지 않은 이유를 모르겠습니다.codeigniter 축소판 그림이이 코드로 생성되지 않았습니다

//UPLOAD IMAGE 
    //some $config vars for image 
    $config['upload_path'] = './images/models'; 
    $config['allowed_types'] = 'gif|jpg|jpeg|png|tif'; 
    $config['max_size'] = '0'; 
    $config['remove_spaces'] = true; 
    $config['overwrite'] = false; 
    $config['max_width'] = '0'; 
    $config['max_height'] = '0'; 

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

    //upload main image 
    if(!$this->upload->do_upload('photo')){ 
     $e = $this->upload->display_errors(); 
     print_r($e); 
    } 

    $image = $this->upload->data(); 

    //print '<pre>'; 
    //print_r($image); exit; 

    if($image['file_name']){ 
     $data['photo'] = "images/models/". $image['file_name']; 
     $data['raw' ] = $image['raw_name']; 
     $data['ext'] = $image['file_ext']; 
    } 


    //create new image 
    $config0['image_library'] = 'gd2'; 
    $config0['source_image'] = $image['full_path']; 
    $config0['new_image'] = "images/models/"."front". $image['file_name']; // you can assign your image name and location 
    $config0['maintain_ratio'] = FALSE; 
    $config0['width'] = 320; 
    $config0['height'] = 270; 

    $this->load->library('image_lib', $config0); 
    if (! $this->image_lib->resize()) 
    { 
    echo $this->image_lib->display_errors(); 
    } 

    //end of new image 



    $config3['image_library'] = 'gd2'; 
    $config3['source_image'] = $image['full_path']; 
    $config3['new_image'] = "images/models/"."main". $image['file_name']; 
    $config3['maintain_ratio'] = FALSE; 
    $config3['width'] = 800; 
    $config3['height'] = 600; 

    $this->load->library('image_lib', $config3); 
    $this->image_lib->initialize($config3); 
    $this->image_lib->resize(); 



    $config4['image_library'] = 'gd2'; 
    $config4['source_image'] = $image['full_path']; 
    $config4['new_image'] = "images/models/"."third". $image['file_name']; 
    $config4['maintain_ratio'] = FALSE; 
    $config4['width'] = 185; 
    $config4['height'] = 125; 

    $this->load->library('image_lib', $config4); 
    $this->image_lib->initialize($config4); 
    $this->image_lib->resize(); 


    //thumbnail creation start 
    $config1['image_library'] = 'gd2'; 
    $config1['source_image'] = $image['full_path']; 
    $config1['create_thumb'] = TRUE; 
    $config1['maintain_ratio'] = FALSE; 
    $config1['width'] = 185; 
    $config1['height'] = 125; 

    $this->load->library('image_lib', $config1); 
    $this->image_lib->initialize($config1); 
    if (! $this->image_lib->resize()) 
    { 
    echo $this->image_lib->display_errors(); 
    } 

    //THUMBNAIL ENDS 
+0

왜 다시 라이브러리를 초기화하지 않고 4 번로드 할 이유가 있습니까? – permawash

답변

2

시도해보십시오. 그것은 당신 것과 거의 비슷합니다. 주석에 오류를 기록하십시오.

//UPLOAD IMAGE 
//some $config vars for image 
$config['upload_path'] = './images/models'; 
$config['allowed_types'] = 'gif|jpg|jpeg|png|tif'; 
$config['max_size'] = '0'; 
$config['remove_spaces'] = true; 
$config['overwrite'] = false; 
$config['max_width'] = '0'; 
$config['max_height'] = '0'; 

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

//upload main image 
if(!$this->upload->do_upload('photo')){ 
    $e = $this->upload->display_errors(); 
    print_r($e); 
}else{ 
    $image = $this->upload->data(); 

    //print '<pre>'; 
    //print_r($image); exit; 

    if($image['file_name']){ 
     $data['photo'] = "images/models/". $image['file_name']; 
     $data['raw' ] = $image['raw_name']; 
     $data['ext'] = $image['file_ext']; 
    } 

    $config1['source_image'] = $image['full_path']; 
    $config1['new_image'] = "images/models/"."front". $image['file_name']; // you can assign your image name and location 
    $config1['maintain_ratio'] = FALSE; 
    $config1['width'] = 320; 
    $config1['height'] = 270; 

    $this->load->library('image_lib', $config1); 
    if (! $this->image_lib->resize()) 
    { 
     echo $this->image_lib->display_errors(); 
     return; 
    } 

    $config1['new_image'] = "images/models/"."main". $image['file_name']; 
    $config1['width'] = 800; 
    $config1['height'] = 600; 

    $this->image_lib->clear(); 
    $this->image_lib->initialize($config1); 
    if (! $this->image_lib->resize()) 
    { 
     echo $this->image_lib->display_errors(); 
     return; 
    } 



    $config1['new_image'] = "images/models/"."third". $image['file_name']; 
    $config1['width'] = 185; 
    $config1['height'] = 125; 

    $this->image_lib->clear(); 
    $this->image_lib->initialize($config1); 
    if (! $this->image_lib->resize()) 
    { 
     echo $this->image_lib->display_errors(); 
     return; 
    } 


    //thumbnail creation start 
    unset($config1['new_image']); 
    $config1['create_thumb'] = TRUE; 

    $this->image_lib->clear(); 
    $this->image_lib->initialize($config1); 
    if (! $this->image_lib->resize()) 
    { 
     echo $this->image_lib->display_errors(); 
     return; 
    } 
    echo "Ok"; 
} 

//THUMBNAIL ENDS 
0

서버 측 파일 시스템 쓰기 작업에서 가장 일반적인 문제는 사용 권한 부족입니다. 한눈에 코드가 당신이 당신의 thumbmail 디렉토리가 쓰기 가능한 것을 확인할 수 있습니다, 나에게 좋아 보인다, 디렉토리 777

+0

디렉토리는 쓰기 가능합니다. 썸네일을 움직이면 파일 생성 바로 아래 (다른 이미지를 생성하는 위)에 썸네일 생성 블록이 작동하지만 맨 아래에 썸네일 블록을 생성하면 작동하지 않습니다. – ktm

2

이미지 조작 클래스가 디자인 된 방법을 -ing chmod와 시도, 당신이 원한다면 더 그것을 사용하는 것입니다 동일한 스크립트 내에서 한 번만 실행하면 처리 할 이미지 사이에

$this->image_lib->clear(); 

사이의 이미지를 실행해야합니다.

이 이전의 모든 설정을 해제하고 당신에게 다음 작물에 대한 깨끗한 상태를 제공합니다은// 워터 마크/어떤 ...

+0

그 중 하나는 도움이되지 않았습니다. 새로운 이미지를 생성하고 썸네일을 생성 한 후에가 아니다. – ktm

+0

'image_lib-> clear()'는 모든 설정을 기본값으로 다시 설정하지 않는다. 따라서 각 구성을 사용하여 일부 기본값을 재설정해야 할 수도 있습니다. 모든 세부 사항을 기억할 수는 없지만이 문제가 여러 이미지 기능을 수행 할 때 예상치 못한 결과를 초래한다는 것을 알고 있습니다. – permawash

0

이 문제는 이미지 생성을의 경로 불일치로 인해 수 있습니다 돌립니다. url 앞에 FCPATH 상수를 사용해보십시오. 그게 도움이 될거야.

관련 문제