CI 묻고 답하기

제목 섬네일 이미지 작업중 이미지 상하반전이 안됩니다...
글쓴이 boorangza 작성시각 2016/07/26 17:20:06
댓글 : 1 추천 : 0 스크랩 : 0 조회수 : 14031   RSS

코드이그나이터 3.0 버전을 사용중입니다.

섬네일 이미지 작업을 하고있습니다.

정사각형의 섬네일을 만드는 작업을 하려고합니다.

이론상으론 예를 들어 150 x 50 인 이미지가 있다고 한다면

정사각형의 섬네일이 되기위하여 양옆의 50픽셀씩을 잘라야 하는상황입니다.

때문에 왼쪽에서 50을 자르고 이미지를 반전하여 50을 자르는 식으로 프로그래밍을 하였습니다.

라이브러리는 imagemagick 을 사용하고있습니다.

crop기능과 resize기능 rotate 기능 모두 잘 작동합니다.

그런데 50 x 150 인 작업물을 작업할때 문제가 발생합니다.

rotate기능중 상하 반전기능에서 자꾸 아무 반응이 없습니다.

gd2라이브러리를 사용할경우 잘 작동하지만 이미지가 겹쳐 생성되고 이미지가 깨지는현상이 발생합니다.

때문에 imagemagick 라이브러리를 사용하게되었습니다.

아이러니한건 좌우반전은 잘됩니다...

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

if(!$this->upload->do_upload("user_file")){
    $error = "1";
    return $error;
} else {
    $data = $this->upload->data();
    list($w, $h) = getimagesize($dir_name.'/'.$data['file_name']);
    if($w > $h){
        $w = ($w - $h)/2;
        $h = '0';
    } else {
        $w = '0';
        $h = ($h - $w)/2;
    }
    $config['image_library'] = 'imagemagick';
    $config['library_path'] = '/usr/bin/';
    $config['source_image'] = $dir_name.'/'.$data['file_name'];
    $config['x_axis'] = $w;
    $config['y_axis'] = $h;
    $this->image_lib->initialize($config);

    if ( ! $this->image_lib->crop())
    {
        echo $this->image_lib->display_errors();
    } else {
        $config['image_library'] = 'ImageMagick';
        $config['library_path'] = '/usr/bin/';
        $config['source_image'] = $dir_name.'/'.$data['file_name'];
        $config['rotation_angle'] = 'hor';
        $this->image_lib->initialize($config);

        if ( ! $this->image_lib->rotate())
        {
            echo $this->image_lib->display_errors();
        } else {
            $config['image_library'] = 'ImageMagick';
            $config['library_path'] = '/usr/bin/';
            $config['source_image'] = $dir_name.'/'.$data['file_name'];
            $config['rotation_angle'] = 'vrt';
            $this->image_lib->initialize($config);

            if ( ! $this->image_lib->rotate())
            {
                echo $this->image_lib->display_errors();
            }
        }
    }

 

위와같은 코드로 사용중이고 

$config['rotation_angle'] = 'hor'; 는 작동하는데
$config['rotation_angle'] = 'vrt'; 은 작동하지 않습니다...

왜일까요... 이미지 라이브러리도 직접가서 소스를 살펴보고 이런저런 방법을 알아보았지만 답이 나오지않아 이렇게

도움을 요청드립니다.. ㅠㅠ 

 다음글 안녕하세요 ciboard로 공부 중인 사람입니다. (1)
 이전글 코드이그나이터 예제 샘플소스 구할만한 곳이 없을까요? (1)

댓글

boorangza / 2016/07/28 15:01:28 / 추천 0

정답인지는 모르겠지만 image_lib.php 안에

imagemagick 소스부분에서 상하반전에대한 소스가 없는것 같아서 추가하는 식으로 해결해보았습니다.

*시존소스

elseif ($action === 'rotate')
{
    
$angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
         ? '-flop' : '-rotate '.$this->rotation_angle;


   $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
}

*수정소스

elseif ($action === 'rotate')
{
   if($this->rotation_angle === 'hor'){
      $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
         ? '-flop' : '-rotate '.$this->rotation_angle;
   } else if($this->rotation_angle === 'vrt'){
      $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
         ? '-flip' : '-rotate '.$this->rotation_angle;
   }


   $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
}