图片格式转换之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图片格式的转换!

对于非图像领域的工作者来讲,能这样转换就足够了。

原文地址:https://www.cnblogs.com/yoyotl/p/5411556.html