본문 바로가기
Server&OS/Linux

[php]섬네일 편하게 만들기/Imagemagick

by 백룡화검 2010. 8. 17.
1. Imagemagick 설치

wget ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/ImageMagick-6.5.8-10.tar.gz
tar zxvf ImageMagick-6.5.8-10.tar.gz
cd ImageMagick-6.5.8-10.tar.gz
./configure
make && make install

2. 정상적으로 설치되었나 확인

cd images (logo.gif 파일이 있는 경로로 이동)
/usr/local/bin/convert logo: logo.gif

3. 에러 발생시
테스트시에 아래와 같은 에러가 출력된다면

/usr/local/bin/convert: error while loading shared libraries: libMagickCore.so.2: cannot open shared
object file: No such file or directory

해결방법

ldconfig /usr/local/lib
또는 설치시 prefix 옵션을 준다.

    ldconfig란? 리눅스 상에서 모듈파일(*.so)을 제대로 인식하지 못할때, 다시 읽어 들이는 명령이다.


4. imagick 설치 (pecl.php.net)
사실 ImageMagick만 설치하여도 exec()로 썸네일 생성은 가능하나 추천하는 방법이 아니다.
그러므로 ImageMagick API인 imagick을 설치한다.

wget http://pecl.php.net/get/imagick-2.3.0.tgz

phpize && ./configure    (phpize가 안되면 phpize 설치 참고)
./configure  --with-php-config=/usr/local/php/bin/php-config
make
make install

이후 모듈이 설치된 경로가 나오면
그 경로를 php.ini에 아래처럼 한줄 추가.

extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/imagick.so"

make 시 에러가 발생한다면 다시 이렇게 해보자.
,/configure  --with-php-config=/usr/local/php5.2.9/bin/php-config --with-imagick=/opt/local
make make install

5. 썸네일 테스트하기
imagick 설치파일 압축풀면 안에 example 폴더에 예제가 있다.

<?php
 
/*
    A simple example demonstrate thumbnail creation.
*/
 
/* Create the Imagick object */
$im = new Imagick();
 
/* Read the image file */
$im->readImage( './test.jpg' );

 /* Thumbnail the image ( width 100, preserve dimensions ) */
$im->thumbnailImage( 100, null );
 
/* Write the thumbail to disk */
$im->writeImage( './test.gif' );

/* Free resources associated to the Imagick object */
$im->destroy();
 
?>

위 와 같이 설치후에
썸네일생성시 Magick-Wand관련 에러가 발생한다면

Magick- Wand를 설치


Download the source from http://www.magickwand.org/download/php/

Unzip tarball, and change into directory
Type "phpize" or phpize && ./configure
Type "autoconf" or skip
Type "./configure"
Type "make"
You should end up with the file modules/magicwand.so and copy that to /usr/lib/php4/ or /usr/lib/php/modules (for php5).
You *must* (at least on my system) add the line in your php.ini "extension=magickwand.so
restart apache, and hit kernel/admin/phpinfo.php to make sure you have it installed and running.


http://www.bitweaver.org/wiki/ImageMagick

http://www.magickwand.org/download/php/
출처 : http://dev1.egloos.com/4417467