準備安裝環境:html
1.gcc等編譯工具的準備:c++
yum install -y gcc gcc-c++ make cmake autoconf automake工具
這個通常的vps上都會有默認安裝,檢驗是否已經安裝可用以下命令:測試
rpm -qa|grep gcc .net
rpm -qa|grep make3d
2.libpng和libjpeg等圖片開發包的安裝orm
yum install -y libpng-devel libjpeg-devel libtiff-devel jasper-devel freetype-devel libtool-ltdl-devel*htm
這個的話通常vps是木有的blog
3.下載GMvps
wget http://downloads.sourceforge.net/project/graphicsmagick/graphicsmagick/1.3.22/GraphicsMagick-1.3.22.tar.gz
4.解壓gm
tar -zxvf GraphicsMagick-1.3.22.tar.gz
5.編譯安裝gm
cd GraphicsMagick-1.3.22
./configure '--prefix=/usr/local/GraphicsMagick-1.3.22' '--exec-prefix=/usr/local/GraphicsMagick-1.3.22' '--bindir=/usr/local/GraphicsMagick-1.3.22/bin' '--sbindir=/usr/local/GraphicsMagick-1.3.22/sbin' '--sysconfdir=/usr/local/GraphicsMagick-1.3.22/etc' '--datadir=/usr/local/GraphicsMagick-1.3.22/share' '--includedir=/usr/local/GraphicsMagick-1.3.22/include' '--libdir=/usr/local/GraphicsMagick-1.3.22/lib' '--libexecdir=/usr/local/GraphicsMagick-1.3.22/libexec' '--localstatedir=/usr/local/GraphicsMagick-1.3.22/var' '--sharedstatedir=/usr/local/GraphicsMagick-1.3.22/share/com' '--mandir=/usr/local/GraphicsMagick-1.3.22/share/man' '--infodir=/usr/local/GraphicsMagick-1.3.22/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
在執行完上述命令後會有一段輸出,能夠查看GraphicsMagick支持的圖片格式,在Configured value下爲yes的表示爲支持,PNG、JPEG v1和ZLIB必須爲yes,若不爲yes將按照前提中所寫的進行操做,而後再重複執行上述命令,一直到所有支持爲止,不然將沒法正常進行截圖操做
make && make install
6.配置環境變量
vi /etc/proflie 添加以下配置:
export GMAGICK_HOME="/usr/local/GraphicsMagick-1.3.22"
export PATH="$GMAGICK_HOME/bin:$PATH"
LD_LIBRARY_PATH=$GMAGICK_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
source /etc/profile 生效配置環境
7.使用命令查看GraphicsMagick所支持的圖片格式:
# gm convert -list formats
若是列表中若是顯示PNG、JPEG、GIF等則表示已支持圖片轉換
8.測試安裝是否正常,使用以下命令:
gm convert -resize 100x80^ -gravity Center -crop 100x80+0+0 sample.jpg thumb.jpg
命令說明:gravity 表示中心座標,可選值爲 Center , NorthWest(左上), NorthEast(右上), SouthWest(左下), SouthEast(右下) ,由Center參數即由中心開始向兩邊裁剪,+指定x軸向y軸向的偏移量。sample.jpg/png爲要裁剪的圖片且必須存在,thumb.jpg/png爲裁剪後生成的新圖片,能夠拷貝生成的文件到本地後查看,能正常顯示,則說明全部安裝均正常。
tips:
領導說最近要上線的一個小項目能夠讓我折騰用容器,舒服!!!
參考:
http://zhenghuali168.iteye.com/blog/1441926
http://www.cnblogs.com/hjy9420/p/5064908.html
http://www.jb51.net/LINUXjishu/120332.html