---
title: "GraphicsMagick安装、实时生成缩略图"
author: "stephen830"
date: "2015-05-19T13:39:03Z"
tags: []
categories: ["开源软件"]
slug: "graphicsmagick"
draft: false
lastmod: "2016-04-28T14:50:58Z"
id: 2212467
url: "https://stephen830.iteye.com/blog/2212467"
---

### GraphicsMagick安装、实时生成缩略图

**博客分类：**

- [图像处理技术](http://elf8848.iteye.com/category/178059)

 

**GraphicsMagick资料**

\----------------------------------------------------------------------------

GraphicsMagick官网 [http://www.graphicsmagick.org](http://www.graphicsmagick.org)

GraphicsMagick编程接口  [http://www.graphicsmagick.org/programming.html](http://www.graphicsmagick.org/programming.html)

ImageMagick 程序接口  [http://www.imagemagick.org/api/MagickCore/](http://www.imagemagick.org/api/MagickCore/)

[Im4java 下载地址](http://sourceforge.net/projects/im4java/files/)：[http://sourceforge.net/projects/im4java/files/](http://sourceforge.net/projects/im4java/files/)

IM4JAVA+GraphicsMagick处理网站图片  [http://javantsky.iteye.com/blog/747807](http://javantsky.iteye.com/blog/747807)

 

**GraphicsMagick 实时、动态缩图**

\----------------------------------------------------------------------------

Nginx,L ua\_nginx,GraphicsMagick 灵活自定义缩略图片尺寸大小方案分享

[http://www.iteye.com/topic/1125126](http://www.iteye.com/topic/1125126)

nginx + lua + GraphicsMagick 动态生成指定大小缩图

[http://www.chinaz.com/web/2012/0903/272395.shtml](http://www.chinaz.com/web/2012/0903/272395.shtml)

 

 

 

**Mac OS x 安装 GraphicsMagick**

\----------------------------------------------------------------------------

安装依赖库，参考：[ImageMagick +Jmagick安装](http://elf8848.iteye.com/blog/455675)

 

安装jpeg包

\----------------

brew install libjpeg

安装在了/usr/local/Cellar/jpeg/8d

 

安装jasper包   

\----------------

brew install jasper

安装在/usr/local/Cellar/jasper/1.900.1

 

安装libpng

\----------------

由于是Mac ,所以使用brew包管理器，快速安装

brew install libpng

安装在了/usr/local/Cellar/libpng/1.5.13

 

安装freetype包

\----------------

brew install freetype

安装在了/usr/local/Cellar/freetype/2.4.10

 

安装zlib包

\----------------

系统自带不用安装了

 

自动安装GraphicsMagick 

\----------------

自动安装：brew install GraphicsMagick

安装在了/usr/local/Cellar/graphicsmagick/1.3.17

 

查看安装信息：

zhaorai@zhaomatoMacBook-Pro lib$ gm -version

 

C代码  [![收藏代码](http://elf8848.iteye.com/images/icon_star.png)]()

01. GraphicsMagick 1.3.17 2012-10-13 Q8 http://www.GraphicsMagick.org/
02. Copyright (C) 2002-2012 GraphicsMagick Group.
03. Additional copyrights and licenses apply to this software.
04. See http://www.GraphicsMagick.org/www/Copyright.html for details.
05. Feature Support:
06. Thread Safe              yes
07. Large Files (&gt; 32 bit)   yes
08. Large Memory (&gt; 32 bit)  yes
09. BZIP                     yes
10. DPS                      no
11. FlashPix                 no
12. FreeType                 yes
13. Ghostscript (Library)    no
14. JBIG                     no
15. JPEG-2000                yes
16. JPEG                     yes
17. Little CMS               no
18. Loadable Modules         no
19. OpenMP                   no
20. PNG                      yes
21. TIFF                     no
22. TRIO                     no
23. UMEM                     no
24. WMF                      no
25. X11                      no
26. XML                      yes
27. ZLIB                     yes
28. Host type: x86\_64-apple-darwin11.4.2
29. Configured using the command:
30. ./configure  '--disable-dependency-tracking' '--prefix=/usr/local/Cellar/graphicsmagick/1.3.17'
31. '--enable-shared' '--disable-static' '--disable-openmp' '--with-gs-font-dir=/usr/local/share/ghostscript/fonts'
32. '--without-x' 'CC=/usr/bin/llvm-gcc' 'CFLAGS=-Os -w -pipe -march=core2 -msse4 -mmacosx-version-min=10.7'
33. 'LDFLAGS=-L/usr/local/lib -F/usr/local/Frameworks -L/usr/X11/lib' 'CPPFLAGS=-F/usr/local/Frameworks -I/usr/X11/include'
34. 'CXX=/usr/bin/llvm-g++' 'CXXFLAGS=-Os -w -pipe -march=core2 -msse4 -mmacosx-version-min=10.7'
35. Final Build Parameters:
36. CC       = /usr/bin/llvm-gcc -std=gnu99
37. CFLAGS   = -Os -w -pipe -march=core2 -msse4 -mmacosx-version-min=10.7 -Wall -D\_THREAD\_SAFE
38. CPPFLAGS = -F/usr/local/Frameworks -I/usr/X11/include -I/usr/local/Cellar/freetype/2.4.10/include/freetype2 -I/usr/include/libxml2
39. CXX      = /usr/bin/llvm-g++
40. CXXFLAGS = -Os -w -pipe -march=core2 -msse4 -mmacosx-version-min=10.7 -D\_THREAD\_SAFE
41. LDFLAGS  = -L/usr/local/lib -F/usr/local/Frameworks -L/usr/X11/lib -L/usr/local/Cellar/freetype/2.4.10/lib -L/usr/lib
42. LIBS     = -lfreetype -ljasper -ljpeg -lpng15 -lbz2 -lxml2 -lz -lm -lpthread

 

\* –prefix=/opt/local 让ImageMagick/GraphicsMagick与MacPorts的库文件安装到同一个目录。

如果你想要安装到其它目录，则输入不同的目录路径，如果不声明–prefix，默认会将其安装到/usr/local。

\* –disable-static和–with-modules使得ImageMagick/GraphicsMagick以动态链接库的方式安装，

现在安装ImageMagick/GraphicsMagick只是为了在Ruby中使用，所以我用–without-perl和–without-magick-plus-plus以免去安装Perl和C++的支持

\* –with-quantum-depth=8配置ImageMagick使用8位的色深。默认是16位。参与RMagick Hints & Tips Forum论坛中的讨论Speed up your RMagick apps in 1 easy step了解这个选项有什么作用。

\* –with-gs-font-dir=/opt/local/share/ghostscript/fonts让ImageMagick/GraphicsMagick知道Ghostscript字体安装在哪个角落里。

如果你某个目录里有“标准”的windows TrueType字体，也可以设置–with-windows-font-dir=选项让ImageMagick/GraphicsMagick使用它们。

查看ImageMagick/GraphicsMagick的README.txt文件了解更多选项的信息。

 

 

**手动安装GraphicsMagick** 

\----------------------

手动安装

下载地址  ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/

tar zvxf GraphicsMagick-1.3.17.tar.gz

cd GraphicsMagick-1.3.17

./configure CC=clang --prefix=/usr/local/GraphicsMagick-1.3.17 --with-quantum-depth=16   --enable-shared --enable-static

make

make install

 

注意confiure命令后面的CC=clang。它指定了编译器为Mac下推荐使用的clang。如果没有这个参数，Makefile将会使用系统默认的编译器进行编译，而这个编译器不是GraphicsMagic所推荐的，并且在make的过程中会出现以下错误：

 

C代码  [![收藏代码](http://elf8848.iteye.com/images/icon_star.png)]()

01. Undefined symbols for architecture x86\_64:
02. "\_\_\_builtin\_object\_size", referenced from:
03. \_BlurImageScanlines.omp\_fn.6 in libGraphicsMagick.a(magick\_libGraphicsMagick\_la-effect.o)
04. \_XShearImage.omp\_fn.0 in libGraphicsMagick.a(magick\_libGraphicsMagick\_la-shear.o)
05. \_YShearImage.omp\_fn.1 in libGraphicsMagick.a(magick\_libGraphicsMagick\_la-shear.o)
06. ld: symbol(s) not found for architecture x86\_64
07. collect2: ld returned 1 exit status
08. make\[1]: \*\** \[utilities/gm] Error 1
09. make: \*\** \[all] Error 2
10. \----------
11. ld: symbol(s) not found for architecture x86\_64
12. collect2: ld returned 1 exit status
13. make\[1]: \*\** \[magick/libGraphicsMagick.la] Error 1
14. make: \*\** \[all] Error 2

 

 

最后还是有错，未成功。

（可参考上面“自动安装”时的的./configure设置编译器，应该会成功）

 

手动安装的配置信息：

![](http://dl.iteye.com/upload/attachment/0078/0160/5a503c89-4a35-3425-9adb-561b9588b53b.png)

 

 

**Windows 上安装GM**

\----------------------------------------

1、安装：略

2、信息

![](http://dl.iteye.com/upload/attachment/0079/3006/05346508-6c9a-3cc4-b7b0-afdeb1018445.jpg)

 

 

**常用管理命令**

\--------------------------------------------------------------------------------------------

 

查看版本后安装情况：gm identify -version

结果：：打印出信息

识别图片：gm identify  /Users/zhaorai/Pictures/照片/100CANON-1/IMG\_4108.JPG

结果：/Users/zhaorai/Pictures/照片/100CANON-1/IMG\_4108.JPG JPEG 3648x2736+0+0 DirectClass 8-bit 2.5M 0.000u 0:01

识别图片(高级)：gm identify  -verbose /Users/zhaorai/Desktop/4.png

结果：打印出很多信息。