ä¸è¬çã« ImageMagick ã®ãµã ãã¤ã«ç»åçæã¯é
ãã¨ããã¦ãããããã©ã¼ãã³ã¹ãæ±ããããã·ã¼ã³ã§ã¯ Imlib2 ãªã©ã®ããé«éãªç»åå¦çã©ã¤ãã©ãªã使ããããã¨ãå¤ãã§ãã
Imlib2 ã®é«éãã«ã¤ãã¦ã¯ã以åãImlib2でImageMagickより3倍高速かつ美しいサムネイル画像の生成 - 床のトルストイ、ゲイとするとのことãã¨ããè¨äºã§ç´¹ä»ãã¾ããããã®è¨äºã®ãã³ããã¼ã¯ã«ããã¦ãImlib2 ã«ãããµã ãã¤ã«ç»åã®çæã¯ã ImageMagick ã®3åç¨é«éã§ããã
ãããã ImageMagick 㯠Imlib2 ããç»è³ªããããé«æ©è½ã§ä½¿ãããããä»ãé »ç¹ã«ã¡ã³ããã³ã¹ããã¦ãããã¨ã¦ãããåºæ¥ã¦ãã¾ãããã®ç¹ Imlib2 ã¯ã2004å¹´ããã¡ã³ããã³ã¹ããã¦ããããã»ãã¥ãªãã£ãã¼ã«ãè¦ã¤ãã£ã¦ããåLinuxãã£ã¹ããªãã¥ã¼ã·ã§ã³ãããããããããå½ã¦ã¦ãããããªç¶æ³ã§ãã ImageMagick ãããååã«éããã°ã Imlib2 ããè±å´ãããã¨ãã§ãã¾ãã
ãããªä¸ã ImageMagick ã«ã¤ãã¦èª¿ã¹ã¦ãããã¡ã«ã ããæ¡ä»¶ä¸ã§ Imlib2 ãããé«éã«ãµã ãã¤ã«çæããæ¹æ³ãè¦ã¤ããã®ã§ãç´¹ä»ãã¾ãã
ãã¤ãã® convert ã«ã-define jpeg:size=...ããã¤ããã ãã§10åéããªã
ãããæ¡ä»¶ä¸ã§é«éã«ãã¨æ¸ãã¾ãããããã®æ¡ä»¶ã¨ã¯ã以ä¸ã®2ã¤ã§ãã
- æ¡ä»¶1: å ãã¡ã¤ã«ã JPEG ç»åã§ãããã¨
- æ¡ä»¶2: å ãã¡ã¤ã«ãéãããåã«ãå¤æå¾ã®ç¸¦æ¨ªpxãåãã£ã¦ãããã¨
ãã¨ãã°ã前回の記事 ã®ä¾ã¨åãã4288x2848のJPG画像(4.8MB)ãã180x120pxã®ãµã ãã¤ã«ç»åãä½æãããã¨ãèãã¾ãã
æ®æ®µãªãã ImageMagick ã® convert ã³ãã³ãã使ã£ã¦
convert -resize 180x120 src.jpg dst.jpg
ãªã©ã¨ããã¨ããããã§ãããããã§ãé«éåã®ããã®ãªãã·ã§ã³ãä»ãã¾ãã
convert -define jpeg:size=180x120 -resize 180x120 src.jpg dst.jpg
éãããæ¹æ³ã¨ããã®ã¯ãå®ã¯ãããã ãã§ãã*1
ãã³ããã¼ã¯
4288x2848のJPG画像(4.8MB)ãã180x120pxã®ãµã ãã¤ã«ç»åã以ä¸ã®æ¡ä»¶ã§ãããã10åãã¤çæããå¤æã«ãããæéãæ¯è¼ãã¾ããã
- ImageMagick ã§ã®æ®éã®ãªãµã¤ãºï¼ç¸®å°ã¢ã«ã´ãªãºã ã¯ããã©ã«ãã®Lanczosï¼
- ImageMagick 㧠-define jpeg:size ãªãã·ã§ã³ãä»ããå ´åã®ãªãµã¤ãºï¼åæ§ã«Lanczosï¼
- Imlib2 (imlib2-rubyï¼ ã§ãªãµã¤ãº
ãã³ããã¼ã¯ã®ã³ã¼ãã¯こちら(gist: 488401)ã
çµæã¯ä»¥ä¸ã®ã¨ããã§ãã*2
æ¡ä»¶ | 1æãããã®å¹³åå¤ææéï¼secï¼ | å¤æçµæï¼quality=90ï¼ |
---|---|---|
1. ImageMagickï¼jpeg:size ãªãï¼ | 2.735397 | |
2. ImageMagickï¼jpeg:size ããï¼ | 0.275900 | |
3. Imlib2 | 0.832415 |
以ä¸ã®ããã«ãImageMagick ã®ãµã ãã¤ã«çæã§ã¯ã jpeg:size ãªãã·ã§ã³ãæå®ãããã¨ã§ãæå®ããªãå ´åã«æ¯ã¹ã¦ããã10åé«éã«ãªãã¾ãããImlib2 ã¨æ¯ã¹ã¦ãç´3åã»ã©é«éã«ãªã£ã¦ãã¾ãã
ç»è³ªã«ã¤ãã¦ã¯ãjpeg:size ãªãã·ã§ã³ãã¤ãããã¨ã«ããå¤åã¯ã»ã¨ãã©ããã¾ããã§ããã
ç»è³ªã¯ã»ã¼ãã®ã¾ã¾ã§é«éãªãããã®ãªãã·ã§ã³ãä»ããªãçç±ã¯ãªãã§ããã
ãªãã§éããªãã®ã
ãªã jpeg:size ã§ç»åã®å¤§ãããæå®ããã ãã§ãããã»ã©ã¾ã§ã« JPEG ã®ç¸®å°ãéããªã£ãã®ãã説æãã¾ãã
ãããããã®ãªãã·ã§ã³ã¯ãªããªã®ãã¨ããã¨ãå
¬å¼ããã¥ã¡ã³ãã«ä»¥ä¸ã®ãããªè¨è¿°ãããã¾ãã
ï¼ä»¥ä¸ãCommon Formats -- IM v6 Examplesããæ訳ï¼
-define jpeg:size={width}x{height}
JPEGã©ã¤ãã©ãªã«ãJPEGãã¡ã¤ã«ã®èªã¿è¾¼ã¿ã®ãã³ããä¸ãã¾ãããã®ã¨ããä½æãããç»åã¯ãå°ãªãã¨ããã® width x height ãã大ããªç»åã«ãªãã¾ãã
ããå ¥åç»åã巨大ãªãããã®ãã³ããä¸ãããã¨ã§ãImageMagickã¯å°ããªç»åã¨ãã¦éããããç»åèªã¿è¾¼ã¿æã®ã¡ã¢ãªãå¤§å¹ ã«ç¯ç´ã§ããæ¼ç®ãåçã«é«éåã§ããã§ãããã
ãã®ãªãã·ã§ã³ã¯ããã¾ã§ãã³ãã§ãããªããå®éã«ãã®å¤§ããã®ç»åãå¾ããã¨ãã§ããããã§ã¯ãªãã¨ããç¹ãå¿ããªãã§ãã ããããã®ãã³ãã§æå®ãããµã¤ãºã«è¿ãããã¤ãã以ä¸ã®å¤§ããã®ç»åãå¾ããã¨ã«ãªãã¾ãã
ãã®å
¬å¼ã®èª¬æã§ã¯ãããããã¾ããããã¨ã«ããéããªããããªãã¨ã¯ä¼ãã£ã¦ãã¾ãããã®ãªãã·ã§ã³ã®æåã«ã¤ãã¦ã詳ãã調ã¹ã¦ã¿ã¾ããã
å
ç¨ã®ä¾ã4288x2848 ã®JPEGç»åã 180x120 ã«ãªãµã¤ãºããä¾ã§èª¬æãã¾ãã使ã£ãã³ãã³ãã¯ã以ä¸ã®ã¨ããã§ããã
convert -define jpeg:size=180x120 -resize 180x120 src.jpg dst.jpg
ãã®æã®æåã¯æ¬¡ã®ããã«ãªãã¾ãã
- ImageMagickã¯ã-define jpeg:size ã§ä¸ãããã 180x120 ã src.jpg ã®ãµã¤ãºã¨ãã¦è¨æ¶ãã
- ImageMagick㯠src.jpg ãéããå®éã®ãµã¤ãºã 4288x2848 ã§ãããã¨ãç¥ã
- ImageMagickã¯ãå®éã®ãµã¤ãºã® 1/2(2144x1424)ã1/4(1608x1068)ã1/8(536x356)ã®ä¸ããã 180x120 ã«ä¸çªè¿ããã㤠180x120 ãã大ãããµã¤ãºãé¸ã¶ï¼ãã®å ´åã¯1/8ï¼
- ImageMagickã¯ã src.jpg ã536x356ã®ç»åã¨ãã¦éã
- ImageMagickã¯ã src.jpg ã 536x356 ãã 180x120 ã«ãªãµã¤ãºãã dst.jpg ã¨ãã¦ä¿åãã
å³ã«ããã¨æ¬¡ã®ããã«ãªãã¾ãã
ImageMagick ã¯ã -define jpeg:size={width}x{height} ã¨ãããªãã·ã§ã³ãä¸ããããã¨ãå®éã®ç»åãµã¤ãºã® 1/2ã1/4ã1/8 ã®ãµã¤ãºã®ä¸ããããªãã·ã§ã³ã§æå®ããããµã¤ãºã«è¿ããã®ãé¸ã³ããã®ãµã¤ãºã¨ãã¦ç»åãéãã¾ããã©ããã¦ãããªãã¨ãå¯è½ãªã®ãã¨ããã¨ããã®ä»çµã¯JPEGã®ãã¼ã¿æ§é ã«ç±æ¥ãã¦ãã¾ããJPEGç»åã¯ã8x8ï¼å ´åã«ãã£ã¦ã¯16x16ï¼pxã®å°ããªæ£æ¹å½¢ã®ç»åã®éåãããªã£ã¦ãã¾ãã詳ãã説æã¯ä»ã®è³æã«ä»»ãã¾ããããã®æ§é ãæ´»ããã¦ãImageMagickã§å©ç¨ãã¦ããJPEGã©ã¤ãã©ãªã®libjpegã§ã¯ã1/2ã1/4ã1/8ã®ãµã¤ãºã¸ã®ç¸®å°ã¯é«éã«è¨ç®ã§ããã®ã§ãã
ImageMagickã¯ç»åããã¹ã¦ã¡ã¢ãªä¸ã«å±éããã¨ããç¹æ§ãããã®ã§ãå ç»åã巨大ã§ããã»ã©ã¡ã¢ãªæ¶è²»ã¯æ¿ãããªãããã®ããã®ã¡ã¢ãªç¢ºä¿ã«æéããããã¾ããããã ImageMagick ãé ãã¨è¨ãããåå ã®ã²ã¨ã¤ã§ãããªãµã¤ãºå¦çèªä½ã¯ãé«éãªã¢ã«ã´ãªãºã ï¼ããã©ã«ãã§ã¯Lanczosï¼ã§è¡ãããã®ã§ãå®ã¯ Imlib2 ãªã©ã®ä»ã®ã©ã¤ãã©ãªã«æ¯ã¹ã¦ãé ãããã§ã¯ãªãã®ã§ãã
ãã®ä»çµã¿ãç°¡åã«ç解ããããã«ãconvert ã³ãã³ãã«ããããã°åºåãããã-debugããªãã·ã§ã³ãå ãã¦ã¿ã¾ãã
ã¾ãã¯ã -define jpeg:size=180x120 ãã¤ããªãå ´åã§ãã
$ convert -debug Coder -log %e -resize 180x120 src.jpg dst.jpg Profile: exif, 45952 bytes Profile: xmp, 5079 bytes Profile: iptc, 76 bytes Interlace: nonprogressive Data precision: 8 Geometry: 4288x2848 :
Geometry ã¨ããé
ç®ãã 4288x2848 ã¨åºåããã¦ãã¾ããããã¯ã src.jpg ãæ¬æ¥ã® 4288x2848 ã¨ãã¦éããããã¨ã示ãã¦ãã¾ãã
次ã«ã -define jpeg:size=180x120 ãä»ãã¦ã¿ã¾ãã
$ convert -debug Coder -log %e -define jpeg:size=180x120 -resize 180x120 src.jpg dst.jpg Profile: exif, 45952 bytes Profile: xmp, 5079 bytes Profile: iptc, 76 bytes Scale factor: 23.733333333333334281 Interlace: nonprogressive Data precision: 8 Geometry: 536x356 :
ãã®ã¨ãã Geometry 㯠536x356 ã¨ãªã£ã¦ããããã® src.jpg ã¯ä¸æ¦ãå ç»åã® 1/8 ã§ãã 536x356 ã¨ãã¦éããããã¨ããããã¾ãã
ã¾ã¨ã
ä»åã¯ã ImageMagick ã§ãJPEGç»åã®ç¸®å°ãé常ã®10åéãããæ¹æ³ãç´¹ä»ãã¾ããã使ããã·ã¼ã³ã§ã¯ã©ãã©ã -define jpeg:size ãã¤ãã¦ã¿ã¾ãããã
ãã¾ãï¼ å¤ããã¼ã¸ã§ã³ã®ImageMagickã§ã¯ï¼
ãã® -define jpeg:size ãªãã·ã§ã³ã¯ã ImageMagick-6.5.x 以éãã使ããã¨ãã§ãã¾ããããããåã®ãã¼ã¸ã§ã³ã§ã¯ã-sizeãªãã·ã§ã³ã使ããã¨ã§åæ§ã®å¹æãå¾ããã¾ãã
ãã¾ãï¼ MagickWand ã§ã¯ï¼
convert ã³ãã³ãã®ãªãã·ã§ã³ã¯ -define jpeg:size=... ã§ãããåæ§ã®å¹æã MagickWand ããå¾ãããã«ã¯ã MagickReadImageç ã®åã«
MagickSetOption(wand, "jpeg:size", "180x120");
ãå¼ã¹ã°OKã§ãã
ãã¾ãï¼ GraphicsMagick ã¯ã©ããªã®ï¼
ImageMagick ã®è©±ãããã¨ãå¿ ããImageMagick ããæ´¾çãã GraphicsMagick ã®ã»ããéããï¼ãã¨æãã¦ããã人ãåºã¦ãããã§ããããªãµã¤ãºã«é¢ãã¦ã¯公式のベンチマークでも別にそんな速くないããæå ã§ãã»ããã¢ããã大å¤ãªããã«ææãªé度差ãåºã¾ããã§ããããã¨ãã©ã³ãå ã® ImageMagick ã®ãã¼ã¸ã§ã³ãå¤ããã¦é常ã«ä½¿ãã¥ããã§ãã
*1:ImageMagick-6.4.9 ããã以åã®ãã¼ã¸ã§ã³ã§ã¯ã -define jpeg:size=... ã§ãªã -size=... ã¨ãã¾ã
*2:ååã®è¨äºããCPUã貧弱㪠MacBook Air 11inch ã§è¨æ¸¬ãã¦ããã®ã§ããé ãã§ã