ããã«ã¡ããã¢ããªã±ã¼ã·ã§ã³åºç¤ãã¼ã ã®éæ¨(@a_o_k_i_n_g)ã§ãã好ããªã¿ããã¯ç´ ããã³ãã§ãã
ä»åã¯ããµã¤ãã¦ãºã®ãµã ãã¤ã«äºæ ã«ã¤ãã¦è¨äºãæ¸ãããã¨æãã¾ãããµã¤ãã¦ãºã«éããé常㮠Web ã¢ããªã±ã¼ã·ã§ã³ã§ããµã ãã¤ã«ä½æã¯ããããã¨æãã¾ããããããã©ãããå¤ãæ¶ãã¦ãããµã ãã¤ãªã¹ããå¤ããã¨æãã¾ããããããã®æ代ãçãããµã ãã¤ãªã¹ããå¿«é©ãªãµã ãã¤ã«ã©ã¤ããéãããããç¥è¦ãå ±æãããã¨æãã¾ãã
å¼ç¤¾ã§ã¯ç»åå¤æãã¼ã«ã« ImageMagick ãç¨ãã¦ãããå¾ã£ã¦æ¬ç¥è¦ã¯ ImageMagick åºæã®ãã®ãã»ã¨ãã©ã§ãã
ç»åæ¯è¼ã¯äººéã®ç¼ã§è¡ãã¹ã
ãµã ãã¤ã«å¨ãã«ä½ãä¿®æ£ãå ¥ãããä¿®æ£åå¾ã®ç»åãæ¯è¼ãã¾ããããæ©æ¢°ã«ãããã¤ãåã®æ¯è¼ã§ã¯ç»åã®è¯ãæªãããããã¾ãããé ¼ããã®ã¯äººéã®ç¼ã ãã§ããèç¼ã§ç¢ºèªãã¾ãããã
æ¯è¼ã§ãããã¼ã«ãä½ãã¨è¯ãã§ãããã¨ãã°ãµã¤ãã¦ãºã§ã¯ä¸è¨ã®ããã«ããã©ã¦ã¶ã§ä¿®æ£åå¾ã®ç»åä¸è¦§ãè¦ããããã«ãã¦ãã¾ããäºæä¸çµã§ãä¸å表示ã«ãã¦ã¾ãã
ééç»åãããããããèæ¯ç»åã«ä½ãããè²ãå ¥ããããç»åã«ãã¼ãã¼ãå ¥ãã¦ããã¨ç¢ºèªããããã§ãã
ãªã½ã¼ã¹å¤§éæ¶è²»ã«æ³¨æ
é«ç»ç´ ãªç»åããç»åãµã¤ãºã¯å°ããã¨ãæ°åæã®ç»åãé£çµãã GIF ã¢ãã¡ã®å¤æã¯å¤§éã®ãªã½ã¼ã¹ãæ¶è²»ãã¾ãããã㨠OutOfMemory ã§æ»ãã ã大éã®ãã£ã¹ã¯ IO ãèµ°ã£ãããã¾ããããã¯è¨ãæããã¨ããµã ãã¤ã«ä½æå¦ç㯠DoS ã®ç©´ã«ãªãå¾ããã¨ãããã¨ã§ããå¿ ããªã½ã¼ã¹å¶éãè¡ã£ã¦ããã¾ãããã
ImageMagick ã§ã¯ -limit
ãªãã·ã§ã³ã§ãªã½ã¼ã¹å¶éãã§ãã¾ãã-limit
ãªãã·ã§ã³ã¯å
¥åç»åãæå®ãããããåã«æå®ããªãã¨å¶éããã¾ãå¹ããªãå ´åãããã®ã§æ³¨æãImageMagick 6.7.2 以åã®ãã¼ã¸ã§ã³ã¯åä½ã® MB ãå°æåã§æ¸ãã¦ã大ä¸å¤«ã§ãããã6.7.3 以éã¯å¤§æåã§ãªããã°ãªãã¾ãããå°æåã§æ¸ãã¨ããªãã¤ãæ±ãããã¦ãã¾ãã¾ãã
convert -limit memory 256MB -limit disk 0 src.jpg dst.png
ã¾ãã-limit
ãªãã·ã§ã³ã§ç»åå¤æ 1 åãããã®ãªã½ã¼ã¹æ¶è²»ãæãã¦ãã大éã«åæå®è¡ããããæå³ãããã¾ãããç»åå¤æã®ä¸¦å度ã«ãå¶éãããã¾ãããã
Orientation ãèæ ®ããã
JPEG ã®å ´å㯠EXIF æ
å ±ã« Orientation æ
å ±ãå
¥ã£ã¦ãããã¨ãããã¾ããImageMagick ã§å¤æããé㯠-auto-orient
ãªãã·ã§ã³ãã¤ãã¦åããè£æ£ãã¾ããããOrientation ç»åã®ç¢ºèªã¯ MS ãã¤ã³ãããªã¹ã¹ã¡ã§ãããªããªãããã¤ã³ãã¯ã·ã³ãã«æ
ã« Orientation ãèæ
®ããåãã®è£æ£ãè¡ãããç»åã®ãã¤ãåã®åããã®ã¾ã¾ã®è¡¨ç¤ºããããããã§ãã
EXIF ã« Orientation ã®é ç®ãåå¨ããªããããå¤ãå ¥ã£ã¦ããªãå ´åãããã¾ããOrientation å¤ãæãåºãã¦ä½ããã®æä½ãããå ´åãnull ãã§ãã¯ãå¿ è¦ã§ãã
Orientation ç»åã¯ãã¡ãã®ãµã³ãã«ã便å©ã§ãã http://www.galloway.me.uk/2012/01/uiimageorientation-exif-orientation-sample-images/
ãã ãImageMagick ã¨ããã© Orientation ç»åã®å¤æã§ã¡ãã£ã¨æªããæåãããã¾ããä¸è¨ãµã³ãã«ç»åã® right-mirrored.jpg ã -auto-orient
ãã¤ã㦠png ã«å¤æããã¨ãoffset æ
å ±ããããããªãã¾ãã
$ convert right-mirrored.jpg -auto-orient out.png $ identify out.png out.png PNG 480x640 640x480+160+4294967136 8-bit PseudoClass 256c 13.8KB 0.000u 0:00.000
ãã®ã±ã¼ã¹ã¯ -auto-orient
ãã¤ãã¦ä¸åº¦ JPEG ã«å¤æããæ¹ã㦠PNG ã«å¤æããã¨æ£ããæ
å ±ã®ç»åãå¾ããã¾ãã
$ convert right-mirrored.jpg -auto-orient jpg:- | convert - out.png $ identify out.png out.png PNG 480x640 480x640+0+0 8-bit PseudoClass 256c 14.6KB 0.000u 0:00.000
ééç»åãèæ ®ããã
PNG ã GIF ã¯ééè²ããµãã¼ããã¾ããééç»åããã®ã¾ã¾ JPEG ã«å¤æããã¨èæ¯è²ãé»ã«ãªãã®ã§ãç½ã«ãããå ´åã¯åããµã¤ãºã«ãªãµã¤ãºãã¾ãããã
$ identify src.png src.png PNG 800x600 800x600+0+0 8-bit DirectClass 218KB 0.000u 0:00.000 $ convert src.png -resize 800x600 -extent 800x600 dst.jpg
åºåããå½¢å¼ãééè²ããµãã¼ããã¦ããå ´å㯠-background transparency
ãä»ä¸ããã¨ãã©ãã«ãå°ãªãã§ãã
CMYK ç»åãèæ ®ããã
ç»åãã¼ã¿ã®è²ç©ºéã CMYK ã®å ´åãããã¾ããCMYK ç»åããªãµã¤ãºãããããã¨è²å³ãå¤ãããã¨ãããã®ã§ã-colorspace RGB
ãã¤ãã¾ãããã
ã¾ããCMYK ç»å㯠Java ã§ã®é常æä½ã§ã¯åãæ±ãã§ããªãã¨ããã®ããããã©ããã§ãã
é常ã¯ãã®ãããªæä½ã§èªã¿æ¸ãã§ãã¾ãã
File file = new File("/path/to/cmyk.jpg"); BufferedImage image = ImageIO.read(file); ....
ã§ãã CMYK ã®å ´åä¾å¤ãåºã¾ãã
Exception in thread "main" javax.imageio.IIOException: Unsupported Image Type at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1063) at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1034) at javax.imageio.ImageIO.read(ImageIO.java:1448) at javax.imageio.ImageIO.read(ImageIO.java:1308) at com.cybozu.common.Sample.main(Sample.java:15)
ãããåé¿ããæ¹æ³ãããã¾ãããCMYK å°ç¨ã®ã³ã¼ããæ¸ãããã¯ãImageMagick ã«ä¸ä»»ãã¦ãã¾ã£ãã»ããå¹ççã§ãã
ã°ã¬ã¤ã¹ã±ã¼ã«ç»åãèæ ®ããã
ç½é»ç»åã PNG ã«å¤æããã¨ãå ç»åããæããªãå ´åãããã¾ããããã¯æ¸è²ã¢ã«ã´ãªãºã ã«ããæåã¨æããã¾ããJPEG ã¯ãã«ã«ã©ã¼ç»åãæ±ãã¾ãããé常㮠PNG ã 㨠256 è²ããæ±ããªãã®ã§ãã
åºåå½¢å¼ã« PNG24 ã¾ã㯠PNG32 ãæ示çã«æå®ãã¦è²ç©ºéãåºããã°ç»åãæããªããã«æ¸ã¿ã¾ãããã ã代åã¨ãã¦ãã¡ã¤ã«ãµã¤ãºã¯å¤§ãããªãã¾ãã
ä¸è¨ç»åã¯ãå·¦ããé ã«ãå
ç»å, $ convert gray.jpg dst.png
ã®çµæ, $ convert gray.jpg png32:dst.png
ã®çµæã§ããã¡ãªã¿ã«ãã®ç»åã¯å¼ç¤¾ç¤¾å¡ã®è¿å½±ã§ãã
ç»åãµã¤ãºã®åå¾ã¯ ImageMagick ã§è¡ãã
ç»åã®å¤æ㯠ImageMagick ã«ä»»ããã¨ãã¦ãç»åãµã¤ãºã®åå¾ã¯ã¢ããªã±ã¼ã·ã§ã³ã®ã³ã¼ãã§è¡ããããªãããããã¾ããããããåè¿°ããããã« Java ã® ImageIO 㯠CMYK ç»åã®æ±ãã«é£ããããé常ã®ã³ã¼ãã§ã¯ãµã¤ãºã®åå¾ãè¡ãã¾ãããã¾ããåæ§ã« GIF ã«ã¤ãã¦ã JDK-7131823 : bug in GIFImageReader ã®ãã°ã§èªããªããã¨ãããã®ã§ããµã¤ãºã®åå¾ã¨ããã©ä¿¡é ¼ã¨å®ç¸¾ã®ãã ImageMagick ã«ä»»ããã¹ãã§ãã
ãã ãç»åãµã¤ãºãåå¾ããã³ãã³ããImageMagick ã® identify ã -verbose
ãªãã·ã§ã³ãã¤ããã¨ã¡ã¢ãªå¤§éæ¶è²»ãããã¨ãããã®ã§æ³¨æã§ããããã¯è²ã®çµ±è¨æ
å ±ãåå¾ãã¦ããããã§ãããã-verbose
ãã¤ããå ´åã¯ãidentify ã³ãã³ãã«ã -limit
ãªãã·ã§ã³ãå¹ãã®ã§æå®ãã¾ãããã
ImageMagick ã®ãªãã·ã§ã³ã®é åºã«æ³¨æ
ãªãã·ã§ã³ã¯åããé ã«è©ä¾¡ããã¦ããã®ã§ãé åºã«ãã£ã¦çµæãç°ãªãã¾ãã-resize
㨠-extent
çã®é åºãç°ãªãã¨çµæãç°ãªãã¨ããã®ã¯ç´æã«å¾ãã¾ããããã¨ãã°èæ¯è²ãæå®ãããªãã·ã§ã³ -background
ãªãããé åºã«ãã£ã¦ãªãã·ã§ã³ãå¹ãããå¹ããªãã£ãããããã¨ãããã¾ããç¹°ãè¿ãã«ãªãã¾ããããµã ãã¤ã«ã¯èç¼ã§ç¢ºèªãã¾ãããã
ImageMagick ã® -define jpeg:size ã«æ³¨æ
ä¸è¨ããã°ã§ -define jpeg:size
ã®æç¨æ§ã示ããã¦ãã¾ãã
http://blog.mirakui.com/entry/20110123/1295795409
確ãã«æ¡ä»¶ããããããã°å¤§å¤ç´ æ´ããããªãã·ã§ã³ã§ãããã ãå¤æå¾ã®ãµã¤ãºã大ããå ´åãããã¦ãã¯å
ç»åãµã¤ãºã® 1/3 以ä¸ç¨åº¦ã§ããããããè¶
ãã㨠-define jpeg:size
ãªãã·ã§ã³ãæå®ãã¦ããªãæ以ä¸ã«ã¡ã¢ãªãæ¶è²»ãã¾ãããã¤ã§ãã¤ããã°è¯ãã¨ãããã®ã§ã¯ãªãã®ã§æ³¨æãã¾ããããå¼ç¤¾ã§ã¯ããã®ãªãã·ã§ã³ã¯ãµã¼ãã¹ã®å®å®éç¨ã®ããã«ã¯ç¡ç¨ã¨å¤æããç¾å¨ãã®ãªãã·ã§ã³ã¯å©ç¨ãã¦ãã¾ããã
ImageMagick ãã®ä»
ImageMagick ã®オプションは膨大ã§ãããã®ããããã£ã¦ãããã¥ã¡ã³ããééãã¦ãããã¨ãããã¾ãããããªæã¯ãã£ã¨ãã¼ã¸ä¸é¨ã® Contact US ãã¯ãªãã¯ãã¦ã¬ãã¼ããã¾ããããããåæ ããã¾ããã§ãè¿äºã¯æ¥ãªãã§ãã
ã¾ã¨ã
ImageMagick ã¯ãªãã·ã§ã³ãè¤éã§ãããã«ããé¨åãããã¾ãããããã§ãæ§ã ãªç»åãæ±ããã¨ããä¿¡é ¼ã¯æºããã¾ãããJava ããã®ä»è¨èªã®å種ã©ã¤ãã©ãªã§ãç»åãã¼ã¿ãæ±ããã¨ã¯ã§ããã¨æãã¾ãããæ§ã ãªç»åã«å¯¾å¿ãããã¨ãèããã¨ãã¯ã ImageMagick ã«ä¸ä»»ããã®ãè¯ãããã«æãã¾ãã
ããã§ã¯ããããµã ãã¤ã«ã©ã¤ããï¼