圖片格式轉換之ImageMagick


項目中需要實現一些圖片文件到TIFF文件的轉換,去網上下載了一些第三方軟件。

好的軟件需要收費,免費的存在各種問題。

自己動手,豐衣足食!

眾里尋他千百度,驀然回首,那人就是ImageMagick。

官網鏈接:http://www.imagemagick.org/script/index.php

ImageMagick® is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, JPEG-2000, GIF, TIFF, DPX, EXR, WebP, Postscript, PDF, and SVG. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.

以上的話引用自官網,強大的讓人心跳,而且是開源的!感謝開源!感謝Linux!

一、下載源碼。

二、執行./configure,發現不支持PDF轉換,缺少庫的支持。

1. pdf庫:ftp://ftp.gnu.org/gnu/ghostscript
2. 編譯pdf庫,提示lcms版本過舊
3. lcms庫:http://www.littlecms.com/index.html
4. 編譯lcms2庫,通過。
5. 編譯pdf庫,通過。

一個小插曲:ghostscript編譯不出so文件。
解決辦法:make so && make soinstall,搞定。

 三、后來發現一個更棒的下載依賴庫的地方。

http://www.imagemagick.org/download/delegates/

這是官網提供的庫。

四、重新./configure,編譯,安裝。

 1 Delegate Library Configuration:
 2   BZLIB             --with-bzlib=yes        no
 3   Autotrace         --with-autotrace=no        no
 4   DJVU              --with-djvu=yes        no
 5   DPS               --with-dps=yes        no
 6   FFTW              --with-fftw=yes        no
 7   FlashPIX          --with-fpx=yes        no
 8   FontConfig        --with-fontconfig=yes    no
 9   FreeType          --with-freetype=yes        yes
10   Ghostscript lib   --with-gslib=no        no
11   Graphviz          --with-gvc=yes        no
12   JBIG              --with-jbig=yes        no
13   JPEG v1           --with-jpeg=yes        yes
14   LCMS              --with-lcms=yes        no
15   LQR               --with-lqr=yes        no
16   LTDL              --with-ltdl=yes        no
17   LZMA              --with-lzma=yes        no
18   Magick++          --with-magick-plus-plus=yes    yes
19   OpenEXR           --with-openexr=yes        no
20   OpenJP2           --with-openjp2=yes        no
21   PANGO             --with-pango=yes        no
22   PERL              --with-perl=no        no
23   PNG               --with-png=yes        yes
24   RAQM              --with-raqm=yes        no
25   RSVG              --with-rsvg=no        no
26   TIFF              --with-tiff=yes        yes
27   WEBP              --with-webp=yes        no
28   WMF               --with-wmf=yes        no
29   X11               --with-x=            yes
30   XML               --with-xml=yes        yes
31   ZLIB              --with-zlib=yes        yes

configure執行完畢,大致看到這樣的信息,yes就意味着已經支持的文件或者庫格式。

no就是缺少相關庫的支持或者信息,還有一個原因,編譯開關未打開。

例如安裝gslib庫以后,./configure --with-gslib才能增加對pdf的處理支持。

五、簡單的測試。

convert apple.jpg apple.png

這就實現了jpg圖片到png圖片格式的轉換!

對於非圖像領域的工作者來講,能這樣轉換就足夠了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM