[썸네일]imagemagick을 이용한 썸네일 만들기
컨텐츠 정보
- 23,127 조회
- 5 추천
- 목록
본문
안녕하세요...FireMaker입니다.
프로젝트 진행상 썸네일을 만들어야 하는 경우가 생겨서
어제 하루 종일 삽질하다가 오늘 아침에서야 해결하고 기쁜 마음에 이렇게
Tip을 올리게 되었습니다.
보시고 이상한 점이나 수정 할게 있으면 리플 달아주세요
썸네일을 만들려고 소스를 찾아보니 대부분이 GD를 이용해서 구현을 했더라고요.
근데 이 GD는 gif와 bmp타입을 지원을 안한다고 그러더군요...ㅡ,,ㅡ
정확히 맞는 지는 모르겠지만 해보니 진짜 안되더군요....버젼이 1.3 이전 버전이면
가능하다는 말두 있던데....그것땜시 다 다시 세팅을 할수 도 없구....
그래서 헤메다 헤메다 찾은것이 imagemagick이라는 놈입니다.
홈페이지가서 보시면 알겠지만 linux, window 둘다 있습니다.
둘다 다 잘됩니다....저희 회사가 시스템이 좀 특이해서 테스트서버는 window에 php를
실 서버는 linux에 php라서 둘다 확인해보니 잘되더라구요..
라이센스 부분은....제가 영어가 딸리는 관계로 잘 모르겠습니다.
한번 주의깊에 보시길...
그럼 본론에 들어가서...
http://www.imagemagick.org/
여기로 가셔서 다운로드를 받으시면 됩니다.
먼저 리눅스는
Unix/Linux/Darwin/Cygwin/MinGW Install:
Download the appropriate binary from
ftp://ftp.imagemagick.org/pub/ImageMagick/binaries
ftp://ftp.imagemagick.net/pub/ImageMagick/binaries
Create (or choose) a directory to install the package into and
cd to that directory, for example:
mkdir $HOME/ImageMagick
cd $HOME/ImageMagick
Extract the contents of the package using the command
gzip -dc /path/to/package.tar.gz | tar -xf -
If the 'bin' subdirectory of the extracted package is not
already in your executable search path, add it to your
PATH environment variable. For example
export PATH; PATH="$HOME/ImageMagick:$PATH"
Test ImageMagick to see if it is working
convert "LOGO:" logo.miff
display logo.miff
로 하셔서 테스트 해보시면 되구요
윈도우는
XP, Win2K, WinME, NT, Win98, Win95 Install:
Download
ftp://ftp.imagemagick.org/pub/ImageMagick/binaries/ImageMagick-i686-pc-windows.exe
ftp://ftp.imagemagick.net/pub/ImageMagick/binaries/ImageMagick-i686-pc-windows.exe
and execute it (or "open" it from your browser) to start the installation
program.
로 설치하시면 됩니다.
별루 헤메실 일이 없을듯..
그런 다음 사용하실때는
소스상에서
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function MakeThum($FileName)
{
$ThumFileName = $FileName . ".gif";
$FileName = "../screenshot/" . $FileName;
$ThumFileName = "../screenshot/" . $ThumFileName;
exec ("convert -geometry 400x $FileName $ThumFileName");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
정도면 가능합니다.
조금 설명을 드린다면
exec는 외부 프로그램을 실행시키는 명령어 입니다.
convert는 좀전에 설치한 imagemagick중의 하나인데 메뉴얼에보면
이놈의 옵션중에 하나인
geometry는
geometry <width>x<height>{+-}<x>{+-}<y>{%}{@} {!}{<}{>}
preferred size and location of the Image window.
preferred size and location of the Image window.
By default, the window size is the image size and the location is chosen by you when it is mapped.
By default, the width and height are maximum values. That is, the image is expanded or contracted to fit the width and height value while maintaining the aspect ratio of the image. Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.
If only the width is specified, the width assumes the value and the height is chosen to maintain the aspect ratio of the image. Similarly, if only the height is specified (e.g., -geometry x256), the width is chosen to maintain the aspect ratio.
To specify a percentage width or height instead, append %. The image size is multiplied by the width and height percentages to obtain the final image dimensions. To increase the size of an image, use a value greater than 100 (e.g. 125%). To decrease an image's size, use a percentage less than 100.
Use @ to specify the maximum area in pixels of an image.
Use > to change the dimensions of the image only if its width or height exceeds the geometry specification. < resizes the image only if both of its dimensions are less than the geometry specification. For example, if you specify '640x480>' and the image size is 256x256, the image size does not change. However, if the image is 512x512 or 1024x1024, it is resized to 480x480. Enclose the geometry specification in quotation marks to prevent the < or > from being interpreted by your shell as a file redirection.
When used with animate and display, offsets are handled in the same manner as in X(1) and the -gravity option is not used. If the x is negative, the offset is measured leftward from the right edge of the screen to the right edge of the image being displayed. Similarly, negative y is measured between the bottom edges. The offsets are not affected by "%"; they are always measured in pixels.
When used as a composite option, -geometry gives the dimensions of the image and its location with respect to the composite image. If the -gravity option is present with NorthEast, East, or SouthEast gravity, the x represents the distance from the right edge of the image to the right edge of the composite image. Similarly, if the -gravity option is present with SouthWest, South, or SouthEast gravity, y is measured between the bottom edges. Accordingly, a positive offset will never point in the direction outside of the image. The offsets are not affected by "%"; they are always measured in pixels. To specify the dimensions of the composite image, use the -resize option.
When used as a convert, import or mogrify option, -geometry is synonymous with -resize and specifies the size of the output image. The offsets, if present, are ignored.
When used as a montage option, -geometry specifies the image size and border size for each tile; default is 256x256+0+0. Negative offsets (border dimensions) are meaningless. The -gravity option affects the placement of the image within the tile; the default gravity for this purpose is Center. If the "%" sign appears in the geometry specification, the tile size is the specified percentage of the original dimensions of the first tile. To specify the dimensions of the montage, use the -resize option.
라고 되어있는데...
convert -geometry 400x
정확한 해석은...제가 아까도 말씀드렸지만 영어가 딸려서...^^...공부해야되...ㅡ,.ㅡ
뭐 대충
convert -geometry 400x
요렇게 쓰면 썸네일을 만들때 가로가 400에 고정되고 세로는 그 비율에 맞게 되고
convert -geometry x400
요렇게 쓰면 썸네일을 만들때 세로가 400에 고정되고 가로는 그 비율에 맞게 되는
암튼 써보시고 더 좋은 팁있으면 올려주세요..
쓰다 보니 두서가 없네요..암튼 테클 환영입니다....그럼..^^
프로젝트 진행상 썸네일을 만들어야 하는 경우가 생겨서
어제 하루 종일 삽질하다가 오늘 아침에서야 해결하고 기쁜 마음에 이렇게
Tip을 올리게 되었습니다.
보시고 이상한 점이나 수정 할게 있으면 리플 달아주세요
썸네일을 만들려고 소스를 찾아보니 대부분이 GD를 이용해서 구현을 했더라고요.
근데 이 GD는 gif와 bmp타입을 지원을 안한다고 그러더군요...ㅡ,,ㅡ
정확히 맞는 지는 모르겠지만 해보니 진짜 안되더군요....버젼이 1.3 이전 버전이면
가능하다는 말두 있던데....그것땜시 다 다시 세팅을 할수 도 없구....
그래서 헤메다 헤메다 찾은것이 imagemagick이라는 놈입니다.
홈페이지가서 보시면 알겠지만 linux, window 둘다 있습니다.
둘다 다 잘됩니다....저희 회사가 시스템이 좀 특이해서 테스트서버는 window에 php를
실 서버는 linux에 php라서 둘다 확인해보니 잘되더라구요..
라이센스 부분은....제가 영어가 딸리는 관계로 잘 모르겠습니다.
한번 주의깊에 보시길...
그럼 본론에 들어가서...
http://www.imagemagick.org/
여기로 가셔서 다운로드를 받으시면 됩니다.
먼저 리눅스는
Unix/Linux/Darwin/Cygwin/MinGW Install:
Download the appropriate binary from
ftp://ftp.imagemagick.org/pub/ImageMagick/binaries
ftp://ftp.imagemagick.net/pub/ImageMagick/binaries
Create (or choose) a directory to install the package into and
cd to that directory, for example:
mkdir $HOME/ImageMagick
cd $HOME/ImageMagick
Extract the contents of the package using the command
gzip -dc /path/to/package.tar.gz | tar -xf -
If the 'bin' subdirectory of the extracted package is not
already in your executable search path, add it to your
PATH environment variable. For example
export PATH; PATH="$HOME/ImageMagick:$PATH"
Test ImageMagick to see if it is working
convert "LOGO:" logo.miff
display logo.miff
로 하셔서 테스트 해보시면 되구요
윈도우는
XP, Win2K, WinME, NT, Win98, Win95 Install:
Download
ftp://ftp.imagemagick.org/pub/ImageMagick/binaries/ImageMagick-i686-pc-windows.exe
ftp://ftp.imagemagick.net/pub/ImageMagick/binaries/ImageMagick-i686-pc-windows.exe
and execute it (or "open" it from your browser) to start the installation
program.
로 설치하시면 됩니다.
별루 헤메실 일이 없을듯..
그런 다음 사용하실때는
소스상에서
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function MakeThum($FileName)
{
$ThumFileName = $FileName . ".gif";
$FileName = "../screenshot/" . $FileName;
$ThumFileName = "../screenshot/" . $ThumFileName;
exec ("convert -geometry 400x $FileName $ThumFileName");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
정도면 가능합니다.
조금 설명을 드린다면
exec는 외부 프로그램을 실행시키는 명령어 입니다.
convert는 좀전에 설치한 imagemagick중의 하나인데 메뉴얼에보면
이놈의 옵션중에 하나인
geometry는
geometry <width>x<height>{+-}<x>{+-}<y>{%}{@} {!}{<}{>}
preferred size and location of the Image window.
preferred size and location of the Image window.
By default, the window size is the image size and the location is chosen by you when it is mapped.
By default, the width and height are maximum values. That is, the image is expanded or contracted to fit the width and height value while maintaining the aspect ratio of the image. Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.
If only the width is specified, the width assumes the value and the height is chosen to maintain the aspect ratio of the image. Similarly, if only the height is specified (e.g., -geometry x256), the width is chosen to maintain the aspect ratio.
To specify a percentage width or height instead, append %. The image size is multiplied by the width and height percentages to obtain the final image dimensions. To increase the size of an image, use a value greater than 100 (e.g. 125%). To decrease an image's size, use a percentage less than 100.
Use @ to specify the maximum area in pixels of an image.
Use > to change the dimensions of the image only if its width or height exceeds the geometry specification. < resizes the image only if both of its dimensions are less than the geometry specification. For example, if you specify '640x480>' and the image size is 256x256, the image size does not change. However, if the image is 512x512 or 1024x1024, it is resized to 480x480. Enclose the geometry specification in quotation marks to prevent the < or > from being interpreted by your shell as a file redirection.
When used with animate and display, offsets are handled in the same manner as in X(1) and the -gravity option is not used. If the x is negative, the offset is measured leftward from the right edge of the screen to the right edge of the image being displayed. Similarly, negative y is measured between the bottom edges. The offsets are not affected by "%"; they are always measured in pixels.
When used as a composite option, -geometry gives the dimensions of the image and its location with respect to the composite image. If the -gravity option is present with NorthEast, East, or SouthEast gravity, the x represents the distance from the right edge of the image to the right edge of the composite image. Similarly, if the -gravity option is present with SouthWest, South, or SouthEast gravity, y is measured between the bottom edges. Accordingly, a positive offset will never point in the direction outside of the image. The offsets are not affected by "%"; they are always measured in pixels. To specify the dimensions of the composite image, use the -resize option.
When used as a convert, import or mogrify option, -geometry is synonymous with -resize and specifies the size of the output image. The offsets, if present, are ignored.
When used as a montage option, -geometry specifies the image size and border size for each tile; default is 256x256+0+0. Negative offsets (border dimensions) are meaningless. The -gravity option affects the placement of the image within the tile; the default gravity for this purpose is Center. If the "%" sign appears in the geometry specification, the tile size is the specified percentage of the original dimensions of the first tile. To specify the dimensions of the montage, use the -resize option.
라고 되어있는데...
convert -geometry 400x
정확한 해석은...제가 아까도 말씀드렸지만 영어가 딸려서...^^...공부해야되...ㅡ,.ㅡ
뭐 대충
convert -geometry 400x
요렇게 쓰면 썸네일을 만들때 가로가 400에 고정되고 세로는 그 비율에 맞게 되고
convert -geometry x400
요렇게 쓰면 썸네일을 만들때 세로가 400에 고정되고 가로는 그 비율에 맞게 되는
암튼 써보시고 더 좋은 팁있으면 올려주세요..
쓰다 보니 두서가 없네요..암튼 테클 환영입니다....그럼..^^
관련자료
-
링크
댓글 0
등록된 댓글이 없습니다.