服務器搭建:3.一、openresty圖片壓縮之GraphicsMagick

服務器環境 CentOS6html

版本nginx

openresty   1.7.10.2   下載地址:https://openresty.org/download/ngx_openresty-1.7.10.2.tar.gzweb

更多Openresty版本請參見:http://openresty.org/cn/download.htmlshell

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

更多GraphicsMagick版本請參見:https://sourceforge.net/projects/graphicsmagick/files/graphicsmagick/服務器

安裝GraphicsMagick須要有3個組件支持,固然這是基於我當前系統的版本而言,他們分別是:編碼

 一、libtool-ltdl-devel 這裏用的雲安裝lua

 yum install libtool-ltdl libtool-ltdl-develspa

二、libpng.net

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

一、解壓並進入安裝目錄,執行編譯

./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.二、openresty圖片壓縮之 lua調用GraphicsMagick

相關文章
相關標籤/搜索