CI 묻고 답하기

제목 이미지 처리 질문요!!
글쓴이 작성시각 2013/04/29 15:40:57
댓글 : 6 추천 : 0 스크랩 : 0 조회수 : 13919   RSS
--모델 소스 --
  <?php
class Attache_model extends CI_Model {
    
    var $gallery_path;
    var $gallery_path_url;
    var $file_path;
    
    public function __construct()
{
parent::__construct();
// 생성자 코드에 기능추가
$this->gallery_path= realpath(APPPATH . '../imges');
        $this->file_path= realpath(APPPATH . '../file');
        $this->gallery_path_url = base_url().'imges/';
}
    
    function do_upload()
    {
        $config = array(
            'allowed_types' =>  'jpg|jpeg|gif|png',
            'upload_path'   =>  $this->gallery_path,
            'max_size'   =>  0
        );
        
        $this->load->library('upload',$config);    
        $this->upload->do_upload();
        $image_data = $this->upload->data();
        
        $config = array(
            'source_image'  =>  $image_data['full_path'],
            'new_image'   =>  $this->gallery_path . '/thumbs',
            'maintain_ration'   =>  true,
            'width' =>  150,
            'height'    => 100
        );
        
        $this->load->library('image_lib',$config);
        $this->image_lib->resize();
    }
    
    function do_upload_image($w,$f)
    {
        
        $config = array(
            'allowed_types' =>  'jpg|jpeg|gif|png',
            'upload_path'   =>  $this->gallery_path ."/". $f,
            'max_size'   =>  0
        );
        
        $this->load->library('upload',$config);    
        $this->upload->do_upload();
        $image_data = $this->upload->data();
        if($image_data['image_width']>$w){
            $config = array(
                'source_image'  =>  $image_data['full_path'],
                'maintain_ration'   =>  true,
                'width' =>  $w,
                'height'    => $w/4*3
            );
            
            $this->load->library('image_lib',$config);
            $this->image_lib->resize();
        }
    }
    
    function do_upload_file($f)
    {
        
        $config = array(
            'allowed_types' =>  '*',
            'upload_path'   =>  $this->file_path ."/". $f,
            'max_size'   =>  2000
        );
        
        $this->load->library('upload',$config);    
        $this->upload->do_upload();
        
    }
    
    function get_images()
    {
        $files = scandir($this->gallery_path);
        $files = array_diff($files,array('.','..','thumbs'));
        
        $images = array();
        
        foreach ($files as $file) {
            $images[] = array(
                'url'   =>  $this->gallery_path_url . $file,
                'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
            );
        }
        
        return $images;
        
    }
    
}


$w는 가로사이즈고요, $f는 게시판 이름이에요..

다름이 아니라 do_upload_image에서 원본 사이즈가 제가 정한 사이즈보다 크면 리사이즈 하게 되는데요

리사이즈 되면서 여기에 섬네일생성 기능을 추가하려고 하는데 너무 어렵네요 

메뉴얼에 있는대로 넣어봤는데 이게 중복처리가 안되는거같아요 ㅠ_ㅠ

두 기능 구현하려면 어떻게 해야할가요 ?
 다음글 select_max 사용중 오류 발생 (1)
 이전글 mysql where절이 이상해요 ㅠㅠㅠ (3)

댓글

변종원(웅파) / 2013/04/29 16:35:16 / 추천 0
이미지 config에 $config['create_thumb'] = TRUE; 추가해보세요
/ 2013/04/30 04:55:14 / 추천 0
웅파//
답변감사합니다.
제가 질문을 잘못했네요..
제가 원한건 원본은 제가 정한 게시판크기보다 크면 리사이즈 하고 섬네일(사이즈 240*180)도 만들어서 리스트에 표현하고 싶은데요.  'create_thumb' =>   true, 요항목을 넣으면 원본은 그대로 두고 섬네일만 생성해서 리사이즈 하게 되요 ..
결국 제가 원하는건 섬네일이 2개 생성되야 되는거죠..
가능할거 같아서

이런식으로

function do_upload_image2($w,$f)
    {
        
        $config = array(
            'allowed_types' =>  'jpg|jpeg|gif|png',
            'upload_path'   =>  $this->gallery_path ."/". $f,
            'max_size'   =>  0
        );
        
        $this->load->library('upload',$config);    
        $this->upload->do_upload();
        $image_data = $this->upload->data();
        
        $config = array(
            'source_image'  =>  $image_data['full_path'],
            'new_image'   =>  $this->gallery_path ."/". $f . '/thumbs',
            'maintain_ration'   =>  true,
            'create_thumb'   =>  true,
            'width' =>  240,
            'height'    => 180
        );
        
        $this->load->library('image_lib',$config);
        $this->image_lib->resize();
        
        
        if($image_data['image_width']>$w){
            $config2 = array(
                'source_image'  =>  $image_data['full_path'],
                'maintain_ration'   =>  true,
                'width' =>  $w,
                'height'    => $w/4*3
            );
            
            $this->load->library('image_lib',$config2);
            $this->image_lib->resize();
        }
    }

해봤는데 안되네요 ..

변종원(웅파) / 2013/04/30 09:58:26 / 추천 0
썸네일 여러개 만들때 처음에만 라이브러리 로딩하고 두번째부터는 초기화함수 이용합니다. 매뉴얼 보시면 있어요
변종원(웅파) / 2013/04/30 10:16:04 / 추천 0
 
$config['image_library'] = 'gd2';
                $config['source_image'] = $data['full_path'];
                $config['create_thumb'] = TRUE;
                $config['master_dim'] = 'height';
                $config['maintain_ratio'] = FALSE;
                $config['width'] = 240;
                $config['height'] = $h240;
                $config['thumb_marker']='';
                $config['new_image'] = $data['raw_name'].'_p'.$data['file_ext'];
                $this->load->library('image_lib', $config);
                $this->image_lib->resize();

                $this->image_lib->clear();

                $config['image_library'] = 'gd2';
                $config['source_image'] = $data['full_path'];
                $config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 110;
                $config['height'] =140;
                $config['thumb_marker']='';
                $config['new_image'] = $data['raw_name'].'_w'.$data['file_ext'];
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
/ 2013/04/30 14:45:22 / 추천 0
웅파//
답변 감사합니다.
예제를 보고 clear와 initialize를 이용해서 해당 기능을 구현했습니다,
정말 감사합니다. ^^


/ 2013/04/30 14:45:46 / 추천 0
function do_upload_image2($w,$f)
    {
        
        $config = array(
            'allowed_types' =>  'jpg|jpeg|gif|png',
            'upload_path'   =>  $this->gallery_path ."/". $f,
            'max_size'   =>  0
        );
        
        $this->load->library('upload',$config);    
        $this->upload->do_upload();
        $image_data = $this->upload->data();
        
        $config = array(
            'source_image'  =>  $image_data['full_path'],
            'maintain_ration'   =>  true,
            'new_image' => $this->gallery_path ."/". $f . "/thumbs",
            'width' =>  240,
            'height'    => 180
        );
        
        $this->load->library('image_lib',$config);
        $this->image_lib->resize();
        
        $this->image_lib->clear();
        
        if($image_data['image_width']>$w){
            $config = array(
                'source_image'  =>  $image_data['full_path'],
                'maintain_ration'   =>  true,
                'width' =>  $w,
                'height'    => $w/4*3
            );
            
            $this->image_lib->initialize($config);
            $this->image_lib->resize();
        }
        echo $this->image_lib->display_errors();        
        
    }