您的位置:首页 > 运维架构

服务器搭建:3.1、openresty图片压缩之GraphicsMagick

2016-05-03 00:00 471 查看
摘要: openresty需要对对图片进行压缩,则需要安装GraphicsMagick,当然你也可以选择openresty自身的图片压缩。我这里描述的是 openresty +lua 调用 GraphicsMagick生成压缩。

服务器环境 CentOS6

版本

openresty 1.7.10.2 下载地址:https://openresty.org/download/ngx_openresty-1.7.10.2.tar.gz

更多Openresty版本请参见:http://openresty.org/cn/download.html

GraphicsMagick-1.3.19 下载地址:http://jaist.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/1.3.19/GraphicsMagick-1.3.19.tar.gz

更多GraphicsMagick版本请参见:https://sourceforge.net/projects/graphicsmagick/files/graphicsmagick/

安装GraphicsMagick需要有3个组件支持,当然这是基于我当前系统的版本而言,他们分别是:

1、libtool-ltdl-devel 这里用的云安装

yum install libtool-ltdl libtool-ltdl-devel

2、libpng

http://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.20/libpng-1.6.20.tar.gz

建议 yum安装:

# yum install libpng
# yum install libpng-devel

http://nchc.dl.sourceforge.net/project/libjpeg/libjpeg/6b/jpegsrc.v6b.tar.gz

只有安装了以上3个组件,才会让GraphicsMagick能压缩.jpeg和 .png文件,同时才能令它编译成功。

编译GraphicsMagick

1、解压并进入安装目录,执行编译

./configure '--prefix=/usr/local/GraphicsMagick-1.3.19' '--exec-prefix=/usr/local/GraphicsMagick-1.3.19' '--bindir=/usr/local/GraphicsMagick-1.3.19/bin' '--sbindir=/usr/local/GraphicsMagick-1.3.19/sbin' '--sysconfdir=/usr/local/GraphicsMagick-1.3.19/etc' '--datadir=/usr/local/GraphicsMagick-1.3.19/share' '--includedir=/usr/local/GraphicsMagick-1.3.19/include' '--libdir=/usr/local/GraphicsMagick-1.3.19/lib' '--libexecdir=/usr/local/GraphicsMagick-1.3.19/libexec' '--localstatedir=/usr/local/GraphicsMagick-1.3.19/var' '--sharedstatedir=/usr/local/GraphicsMagick-1.3.19/share/com' '--mandir=/usr/local/GraphicsMagick-1.3.19/share/man' '--infodir=/usr/local/GraphicsMagick-1.3.19/share/info' '--enable-libtool-verbose' '--with-included-ltdl' '--enable-shared' '--disable-static' '--with-modules' '--with-frozenpaths' '--without-perl' '--without-magick-plus-plus' '--with-quantum-depth=8' --enable-symbol-prefix

如果你的版本和安装路径和我的不同,直接去替换内容就行:/usr/local/GraphicsMagick-1.3.19

编码如果没有出现异常,在最后的输出中 肯定会有以下这部分,请注意红色标识位置必须为yes否则后续无法压缩

Option Configure option Configured value
-----------------------------------------------------------------
Shared libraries --enable-shared=yes yes
Static libraries --enable-static=no no
GNU ld --with-gnu-ld=yes yes
Quantum depth --with-quantum-depth=8 8
Modules --with-modules=yes yes

Delegate Configuration:
BZLIB --with-bzlib=yes no
DPS --with-dps=yes no
FlashPIX --with-fpx=no no
FreeType 2.0 --with-ttf=yes no
Ghostscript None /usr/bin/gs (9.07)
Ghostscript fonts --with-gs-font-dir=default /usr/share/fonts/default/Type1/
Ghostscript lib --with-gslib=no no
JBIG --with-jbig=yes no
WEBP --with-webp=yes no
JPEG v1 --with-jpeg=yes yes
JPEG-2000 --with-jp2=yes no
LCMS v1 --with-lcms=yes no
LCMS v2 --with-lcms2=yes no
LZMA --with-lzma=yes no
Magick++ --with-magick-plus-plus=no no
PERL --with-perl=no no
PNG --with-png=yes yes (-lpng16)
TIFF --with-tiff=yes no
TRIO --with-trio=yes no
Windows fonts --with-windows-font-dir= none
WMF --with-wmf=yes no
X11 --with-x= no
XML --with-xml=yes no
ZLIB --with-zlib=yes yes


接下来就是安装的2步操作
# make
# make install

配置环境变量(必要)

vi /etc/profile

在最后位置插入如下配置

export GM_HOME=/usr/local/GraphicsMagick-1.3.19

export PATH=$GM_HOME/bin:$GM_HOME/lib:$PATH

保存退出。

并执行如下命令使它立即生产:

# ldconfig

#source /etc/profile

完成后可以查看GraphicsMagick是否支持了相应图片格式的处理:

# gm convert -list formats

执行后输出结果,请注意查找到以下这些内容(可能不是放在一起的,请自行比对):

GIF P rw+ CompuServe graphics interchange format (version 89a)
JPEG P rw- Joint Photographic Experts Group JFIF format (IJG JPEG 62)
JPG P rw- Joint Photographic Experts Group JFIF format (IJG JPEG 62)
PNG P rw- Portable Network Graphics (libpng 1.2.49, zlib 1.2.3)
See http://www.libpng.org/ for information on PNG..
PNG00 P rw- PNG that inherits type and depth from original (libpng 1.2.49, zlib 1.2.3)
PNG24 P rw- 24-bit RGB PNG, opaque only (libpng 1.2.49, zlib 1.2.3)
PNG32 P rw- 32-bit RGBA PNG, semitransparency OK (libpng 1.2.49, zlib 1.2.3)
PNG48 P rw- opaque or binary transparent 48-bit RGB (libpng 1.2.49, zlib 1.2.3)
PNG64 P rw- opaque or transparent 64-bit RGBA (libpng 1.2.49, zlib 1.2.3)
PNG8 P rw- 8-bit indexed PNG, binary transparency only (libpng 1.2.49, zlib 1.2.3)

会发现,就是图片格式名,这说明他支持这类图片的压缩了。

到此GraphicsMagick就安装完成后,后续与nginx以及lua配合请点击这里: 3.2、openresty图片压缩之 lua调用GraphicsMagick
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息