ãã®è¨äºã®æ¦è¦
Imlib2ã使ã£ã¦ç»åã®ãµã ãã¤ã«ãçæãã¦ã¿ãã¨ãããImageMagickãã3åéãã£ãã
ã¾ãä¸è¬çã«ã¯ãImlib2ã®æ¹ãç»è³ªãæªãã¨ããã¦ãããããã©ã¡ã¼ã¿ã調æ´ãããã¨ã§ãååã«ç¾ãããµã ãã¤ã«ç»åãå¾ããã¨ãã§ããã
ã¯ããã«
Imlib2ã¯ç»åå¦çã©ã¤ãã©ãªãmixiã®çºè¡¨è³æ大規模画像配信とPerl ã«ããã°ãmixiã¯é«éã«é«å質ãªãµã ãã¤ã«ãçæããããã«ãImageMagickã§ãªãImlib2ãé¸ãã§ããã
ä¸è¨è³æã®ä¸ã§ã¯ã以ä¸ã®ããã«èª¬æããã¦ããã
é度 Epeg > Imlib2 > Imager >>> ImageMagick ç»è³ª ImageMagick > Imlib2 >>> Epeg
Imlibã®ç»è³ªã¯å¤å°ImageMagickã«å£ãããé度ã¯ååã«éããã¨ã®ãã¨ã
ä¸æ¹ã§ã404 Not Foundã¨ããè¨äºã§ã¯ãImageMagickã®ãã³ããã¼ã¯è¨äºãç´¹ä»ããã¦ããããã¯ãImageMagickã¯é
ããã¨ããçµè«ã«ãªã£ã¦ãããåè¨äºã§ã¯ãç»åãéãã¦ä¿åããã¨ããã ãã®ãã³ããã¼ã¯ã§ãImageMagickã¨Imlib2ã®é度差ã¯10åå¼±ã®éãããããImageMagickã¯ãã¡ã¤ã«ã®å
¥åºåã®ãªã¼ããããã大ãããã¨ãåããã
ã¨ããããã§ãImlib2ã試ãã¦ã¿ãã
ã¤ã³ã¹ãã¼ã«
Imlib2ã¯Cã§æ¸ããã¦ãããRubyãã¤ã³ãã£ã³ã°ã§ããImlib2-Rubyãå
¬éããã¦ãããããã§ã¯ããã®Imlib2-Rubyã使ã£ã¦Imlib2ã試ããã¨ã«ããã
Imlib2-Rubyã¯ãrubyforgeãªã©ã«ä¸ãã£ã¦ããªããããèªåã§gemããã¦ã³ãã¼ããã¦ã¤ã³ã¹ãã¼ã«ããå¿
è¦ãããã
以ä¸ãMacã®å ´åã
$ sudo port install imlib2 $ wget http://pablotron.org/files/gems/imlib2-ruby-0.5.2.gem $ gem install imlib2-ruby-0.5.2.gem
使ãæ¹ï¼ãµã ãã¤ã«çæï¼
ImageMagickã«ã¯ã便å©ãªGeometry機能ããã£ã¦ãã¢ã¹ãã¯ãæ¯ã«ã¤ãã¦ããã«ã¯ããã£ã¦ãããããImlib2ã§ã¯èªåã§è¨ç®ããå¿
è¦ãããã
ã¨ããããã横å¹
180px*1ã«ãªãµã¤ãºãã¦ã¿ãã
require 'rubygems' require 'imlib2' img = Imlib2::Image.load("1.jpg") new_w = 180 new_h = ((new_w.to_f / img.w) * img.h).round img.crop_scaled!(0, 0, img.w, img.h, new_w, new_h) img.save("out.jpg")
ããã§æ¨ªå¹
180pxã®out.jpgãä½æãããã
Imlib2ã«ã¯cropã¨scaleãåæã«è¡ãã¡ã½ãããããªããscaleã®ã¿ãåä½ã§è¡ããã¨ãã§ããªãããã ãRubyãã¤ã³ãã£ã³ã°ãææããªã®ãã¨æã£ãããå
ã®C APIã«ãそのようなメソッドが無いã®ã§ããããããã®ãããã
ImageMagickã¨ã®æ¯è¼1: é度
ImageMagick(RMagick)ã¨Imlib2(Imlib2-Ruby)ãç¨ãã¦ã両è ã®ãµã ãã¤ã«ä½æé度ãæ¯è¼ããã
ãã¹ãç°å¢
- MacBook Pro
- CPU: 3.06GHz Intel Core 2 Duo
- Mem: 8GB
- Ruby 1.8.7-p174 (Imlib2-RubyãRuby1.9ã«ã¯ã¤ã³ã¹ãã¼ã«ã§ããªãã£ãï¼
- imlib2 1.4.2, Imlib2-Ruby 0.5.2
- ImageMagick 6.5.4 Q16, RMagick 2.13.1
ã³ã¼ã
4288x2848ã®JPGç»å(4.8MB)ãã横å¹
180pxã®ãµã ãã¤ã«ã10åãã¤ä½æããå¹³åé度ãæ¯è¼ããã
ãã³ããã¼ã¯ã®ã³ã¼ãã¯ä»¥ä¸ã«ä¸ãã¦ããã
Benchmark Imlib2 vs ImageMagick — Gist
çµæ
ã©ã¤ãã©ãª | 1æãããã®å¤ææé |
---|---|
ImageMagick | 1.061849 sec |
Imlib2 | 0.348064 sec |
ç´3.05åImlib2ã®æ¹ãé«éã ã£ãã確ãã«ãéãã
ImageMagickã¨ã®æ¯è¼2: å¤æå¾ã®ãã¡ã¤ã«ãµã¤ãº
ãµã ãã¤ã«å¤æå¾ã®ãã¡ã¤ã«ãµã¤ãºãæ¯è¼ããã
ã©ã¤ãã©ãª | å¤æå¾ã®ãã¡ã¤ã«ãµã¤ãº |
---|---|
ImageMagick | 59.0KB |
Imlib2 | 5.0KB |
ImageMagickã®æ¹ãç´11.8å大ããã£ãããã®å·®ãç»è³ªã®å·®ã«ãç¾ãã¦ããã®ãããããªããã¨ãã®æç¹ã§ã¯æã£ãã
ImageMagickã¨ã®æ¯è¼3: ç»è³ª
ä¸è¨ã®å®é¨ã§çæããããµã ãã¤ã«ç»åã®ç»è³ªãç®è¦ã§æ¯è¼ããã
元画像
ImageMagick | Imlib2 |
---|---|
59.0KB | 5.0KB |
俺ã«ã¯æãããªéããããããã«è¦ãããèã®ã¨ãã¸ã«æ³¨ç®ãããããã©ã£ã¡ã®ãã³ãã³ã¸ã¼ãç¾å³ãããã«è¦ããã ãããï¼
æ¡å¤§ãã¦ã¿ããï¼å·¦:ImageMagick, å³:Imlib2ï¼
Imlib2ï¼å³ï¼ã®æ¹ã¯ãèã¨ç¿ãç¿ã¨æºã®å¢çãèããªã£ã¦ããã®ãåãããé£æã®è¼ªéãã¼ããã¦ããã
ãã ãç»è³ªã«éããããã¨è¨ã£ã¦ãããã¡ã¤ã«ãµã¤ãºã¯12åè¿ãéãããã§ãç»è³ªãæ¯è¼ããã®ã¯é
·ã¨ãããã®ã ã
Imlib2ã§ç»è³ªã調æ´ãã¦ã¿ã
Imlib2-Rubyã®ã½ã¼ã¹ã³ã¼ããèªãã§ãããã以ä¸ã®ããã«ãã¦åºåç»åã®ã¯ãªãªãã£ã調æ´ã§ãããã¨ã«æ°ã¥ããã
img.crop_scaled!(0, 0, img.w, img.h, new_w, new_h) img['quality'] = 80 # ãã®ããã«ãã¦ã¯ãªãªãã£ã調æ´ã§ããããããå¤åã¯ãã¶ã 0ã100 img.save("out.jpg")
ã¯ãªãªãã£ã 80, 90, 100 ã«ãã¦ã¿ã¦ãå¤æé度ããã³ãã¡ã¤ã«ãµã¤ãºãç»è³ªãæ¯è¼ãã¦ã¿ãã
ã¯ãªãªã㣠| ããã©ã«ã | 80 | 90 | 100 |
---|---|---|---|---|
ç»å | ||||
ãã¡ã¤ã«ãµã¤ãº | 5.0KB | 5.4KB | 7.6KB | 20KB |
å¤ææé | 0.363925 sec | 0.332079 sec | 0.332087 sec | 0.329928 sec |
qualityå¤ãæå®ããªãã£ãå ´åã®ããã©ã«ãã®qualityã¯åãããªãããã ããquality=80ã®ã¨ãããããã¡ã¤ã«ãµã¤ãºãå°ããã®ã§ã80以ä¸ã§ããããã¨ãäºæ³ã§ããã
qualityãæå®ãã¦ããå¤ææéã«ã¤ãã¦ã¯ææãªå·®ãè¦ãããªãã£ãã
æ¡å¤§ãã¦ã¿ããï¼å·¦ãããããã©ã«ãã80ã90ã100ï¼
ãããã«100ã¯ç¶ºéºã§ããããããã¯ãã¤ãºãè¦ãããªãã90ã¨ãªãã¨ãå¤å°ãããã¯ãã¤ãºãåºã¦ãããããµã ãã¤ã«ãèç¼ã§è¦ã¦ããã¾ãå·®ããªããã¨ããã90ãªã許容ã§ããç¨åº¦ã®ç¾ããã§ããã¨æãããWebãµã¼ãã¹ãªã©ã§ããã¡ã¤ã«ãµã¤ãºã«ã·ãã¢ã§ãããããã«ç»è³ªãæ±ããããå ´åã«ã¯ãquality=90ã«ããã®ãããã ããããªã«ããã90ã¨100ã§ã¯ãã¡ã¤ã«ãµã¤ãºãå以ä¸éãã
ããã©ã«ãããã³80ã«ã¤ãã¦ã¯ããããã¯ãã¤ãºãæ°ã«ãªã£ãã
ImageMagickåã³
æå¾ã«ãImageMagickã§çæãããµã ãã¤ã«ã¯ãä¸è¬çã«è¨ããã¦ããããã«ãæ¬å½ã«Imlib2ãã綺éºãªã®ããå度æ¯è¼ãã¦ã¿ãã
å·¦ãããImageMagickãImlib2(quality=90)ãImlib2(quality=100)ã§ããã
ãããã¯ãã¤ãºã¨ãã観ç¹ã§ã¯ãImageMagickã®åºåã¯ãImlib2(quality=90)ã«å£ã£ã¦ããããã«è¦ãããï¼ããããé£æã®ç«ä½æã«ã¤ãã¦ã¯ImageMagickã®æ¹ãä¸åã£ã¦ããããã«æãããï¼
ããã«ããã¡ã¤ã«ãµã¤ãºããã³å¤ææéãæ¯ã¹ã¦ã¿ãã
ã©ã¤ãã©ãª | ã¯ãªãªã㣠| å¤æå¾ã®ãã¡ã¤ã«ãµã¤ãº | å¤ææé |
---|---|---|---|
ImageMagick | ããã©ã«ã | 59.0KB | 1.061849 sec |
Imlib2 | 90 | 7.6KB | 0.332087 sec |
Imlib2 | 100 | 20.0KB | 0.329928 sec |
Imlib2ã§æé«ç»è³ªã®ãµã ãã¤ã«ãçæãã¦ããImageMagickãããã¡ã¤ã«ãµã¤ãºãå°ããã¨ããç¹ã«æ³¨ç®ããããã
ä»åã®æ¡ä»¶ä¸ã«ããã¦Imlib2ã¯ãå¤ææéããã¡ã¤ã«ãµã¤ãºãç»è³ªã¨ãã«ImageMagickã«åªã£ã¦ããã
追è¨ï¼2010/07/24ï¼
ImageMagickã®ç»åã®ãã¡ã¤ã«ãµã¤ãºã大ããã®ã¯ãEXIFæ å ±ãå«ã¾ãã¦ããããã ããã§ãããããåãé¤ããã¨ã§ããã¡ã¤ã«ãµã¤ãºãæãããã¨ãå¯è½ã§ãã
ã¾ã¨ã
Imlib2ã使ã£ã¦ç»åã®ãµã ãã¤ã«ãçæãã¦ã¿ãã¨ãããImageMagickãã3åéãã£ãã
ã¾ãä¸è¬çã«ã¯ãImlib2ã®æ¹ãç»è³ªãæªãã¨ããã¦ããããqualityãã©ã¡ã¼ã¿ã調æ´ãããã¨ã«ãããé«å質ã®ãµã ãã¤ã«ç»åãå¾ããã¨ãã§ããã
ãã ãåç¨åº¦ã®ãããã¯ãã¤ãºãå
¥ã£ãç»åãæ¯è¼ããå ´åãImageMagickã®åºåã®æ¹ãç«ä½æããããImlib2ã®åºåã¯å¤å°ã®ã£ãºãã¨ããå°è±¡ãå¦ããªãã
ç»è³ªã®æ£ç¢ºãªæ¯è¼ã®ããã«ã¯ImageMagickã«ãããç»è³ªã®ãã¥ã¼ãã³ã°ãè¡ãã¹ãã§ããããImageMagickã¯ããããå
¥åºåã®é度ãImlib2ã«å£ã£ã¦ããã®ã§ããã以ä¸ã¯è¿½ç©¶ããªãã£ãã
è足
Imlib2-Rubyã®å ¬å¼ãµã¤ãã«ç½®ããã¦ãããµã³ãã«ç»åãひどいããã®ç»åã¯Imlib2-Rubyã«ãå梱ããã¦ããã大å¤ã«ã¯ã¬ã¤ã¸ã¼ã
åèè³æ
- Léon Brocard / Image-Imlib2-2.03 - search.cpan.org
- Imlib2ã®Perlãã¤ã³ãã£ã³ã°ãmixiã§å©ç¨ããã¦ããã¨æããããç´ç²ã«C APIã移æ¤ãã¦ããImlib2-Rubyã¨æ¯ã¹ãscaleã¨cropãåé¢ãã¦ãã£ãããã¦ãç¬èªã®è¨è¨ã«ãªã£ã¦ããã
-
- MacPortsã®Imlib2ã
- Imlib2-Ruby API Documentation
- Imlib2-Rubyã®ããã¥ã¡ã³ãã
- ロングテールな画像配信 その1 - mixi Engineers' Blog
- mixiã®è¨äº
- ロングテールな画像配信 その2 - 3,000万の画像を配信するシステム - mixi Engineers' Blog
- mixiã®è¨äº