GraphicsMagick号称图像处理领域的瑞士军刀。 短小精悍的代码却提供了一个鲁棒、高效的工具和库集合,来处理图像的读取、写入和操作,支持超过88种图像格式,包括重要的DPX、GIF、JPEG、JPEG-2000、PNG、PDF、PNM和TIFF。
通过使用OpenMP可是利用多线程进行图片处理,增强了通过扩展CPU提高处理能力。GraphicsMagick可以再绝大多数的平台上使用,Linux、Mac、Windows都没有问题。
GraphicsMagick支持大图片的处理,并且已经做过GB级别的图像处理实验。GraphicsMagick能够动态的生成图片,特别适用于互联网的应用。可以用来处理调整尺寸、旋转、加亮、颜色调整、增加特效等方面。GaphicsMagick不仅支持命令行的模式,同时也支持C、C++、Perl、PHP、Tcl、Ruby等的调用。事实上,GraphicsMagick是从 ImageMagick 5.5.2 分支出来的,但是现在他变得更稳定和优秀。
GraphicsMagick官网:http://www.graphicsmagick.org/index.html 目前最新版本为 1.3.26
安装建议:
先解压GraphicsMagick-1.3.26.tar.gz包 ./configure 检查png与jpg的支持情况,如不支持,请安装相应的图片库之后再安装GM服务。
安装一些基础包:
yum install libtool* libpng.x86_64 libpng-devel.x86_64 libpng-static.x86_64
安装常见图片库jpeg及png
建立jpeg安装目录
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/include
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/man
mkdir /usr/local/jpeg6/man/man1
解压安装jpeg
tar xvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
cp /usr/share/libtool/config/config.sub .
cp /usr/share/libtool/config/config.guess .
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make
make install
64位系统以上两个cp务必执行,否则会报错
make: ./libtool:命令未找到
make: * [jcapimin.lo] 错误 127
安装libpng库
tar xvf libpng-1.4.12.tar.gz
cd libpng-1.4.12
./configure --prefix=/usr/local/png --enable-shared
make
make install
安装GraphicsMagick
tar xvf GraphicsMagick-1.3.26.tar.gz
cd GraphicsMagick-1.3.26
./configure --prefix=/usr/local/graphicsMagick CPPFLAGS='-I/usr/local/png/include -I/usr/local/jpeg6/include' LDFLAGS='-L/usr/local/png/lib -L/usr/local/jpeg6/lib' --enable-shared
make
make install
添加环境变量
vim /etc/profile
IM4JAVA_TOOLPATH=/usr/local/graphicsMagick/bin
export IM4JAVA_TOOLPATH
soure /etc/profile
运行gm --version会显示版本信息及支持那些图片库等信息:
[root@waibao_121_180 tmp]# gm -version
GraphicsMagick 1.3.26 2017-07-04 Q8 http://www.GraphicsMagick.org/
Copyright (C) 2002-2017 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.
Feature Support:
Native Thread Safe yes
Large Files (> 32 bit) yes
Large Memory (> 32 bit) yes
BZIP yes
DPS no
FlashPix no
FreeType yes
Ghostscript (Library) no
JBIG no
JPEG-2000 no
JPEG yes
Little CMS no
Loadable Modules no
OpenMP yes (200805)
PNG yes
TIFF no
TRIO no
UMEM no
WebP no
WMF no
X11 yes
XML yes
ZLIB yes
Host type: x86_64-unknown-linux-gnu
Configured using the command:
./configure 'CPPFLAGS=-I/usr/local/png/include -I/usr/local/jpeg6/include' 'LDFLAGS=-L/usr/local/png/lib -L/usr/local/jpeg6/lib' '--enable-shared'
Final Build Parameters:
CC = gcc -std=gnu99
CFLAGS = -fopenmp -g -O2 -Wall -pthread
CPPFLAGS = -I/usr/local/png/include -I/usr/local/jpeg6/include -I/usr/include/freetype2 -I/usr/include/libxml2
CXX = g++
CXXFLAGS = -pthread
LDFLAGS = -L/usr/local/png/lib -L/usr/local/jpeg6/lib
LIBS = -lfreetype -ljpeg -lpng14 -lXext -lSM -lICE -lX11 -lbz2 -lxml2 -lz -lm -lgomp -lpthread
使用gm convert -list formats查看支持所有的图片格式:
[root@waibao_121_180 tmp]# gm convert -list formats
Format L Mode Description
--------------------------------------------------------------------------------
3FR S r-- Hasselblad Photo RAW
8BIM P rw- Photoshop resource format
8BIMTEXT P rw- Photoshop resource text format
8BIMWTEXT P rw- Photoshop resource wide text format
APP1 P rw- Raw application information
APP1JPEG P rw- Raw JPEG binary data
ART S rw- PFS: 1st Publisher
ARW S r-- Sony Alpha DSLR RAW
AVS U rw+ AVS X image
B S rw+ Raw blue samples
BMP P rw- Microsoft Windows bitmap image
BMP2 P -w- Microsoft Windows bitmap image v2
BMP3 P -w- Microsoft Windows bitmap image v3
C S rw+ Raw cyan samples
CACHE U --- Magick Persistent Cache image format
CALS S rw- Continuous Acquisition and Life-cycle Support Type 1 image
Specified in MIL-R-28002 and MIL-PRF-28002
CAPTION P r-- Image caption
CIN S rw- Cineon Image File
CMYK S rw+ Raw cyan, magenta, yellow, and black samples
CMYKA S rw+ Raw cyan, magenta, yellow, black, and opacity samples
CR2 S r-- Canon Photo RAW
CRW S r-- Canon Photo RAW
CUR S r-- Microsoft Cursor Icon
CUT S r-- DR Halo
DCM S r-- Digital Imaging and Communications in Medicine image
See http://medical.nema.org/ for information on DICOM.
DCR S r-- Kodak Photo RAW
DCX S rw+ ZSoft IBM PC multi-page Paintbrush
DNG S r-- Adobe Digital Negative
DPX P rw- SMPTE 268M-2003 (DPX 2.0)
See http://www.smtpe.org/ for information on DPX.
EPDF P rw- Encapsulated Portable Document Format
EPI P rw- Adobe Encapsulated PostScript Interchange format
EPS P rw- Adobe Encapsulated PostScript
EPS2 P -w- Adobe Level II Encapsulated PostScript
EPS3 P -w+ Adobe Level III Encapsulated PostScript
EPSF P rw- Adobe Encapsulated PostScript
EPSI P rw- Adobe Encapsulated PostScript Interchange format
ERF S r-- Epson RAW Format
EXIF P rw- Exif digital camera binary data
FAX P rw+ Group 3 FAX (Not TIFF Group3 FAX!)
FILE S r-- Uniform Resource Locator (file://)
FITS S rw- Flexible Image Transport System
FRACTAL P r-- Plasma fractal image
FTP U r-- Uniform Resource Locator (ftp://)
G S rw+ Raw green samples
GIF P rw+ CompuServe graphics interchange format (version 89a)
GIF87 P rw- CompuServe graphics interchange format (version 87a)
GRADIENT P r-- Gradual passing from one shade to another
GRAY S rw+ Raw gray samples
GRAYA S rw+ Raw gray samples + alpha
HISTOGRAM P -w- Histogram of the image
HRZ S r-- HRZ: Slow scan TV
HTML P -w- Hypertext Markup Language and a client-side image map
HTTP U r-- Uniform Resource Locator (http://)
ICB S rw+ Truevision Targa image
ICC P rw- ICC Color Profile
ICM P rw- ICC Color Profile
ICO S r-- Microsoft Icon
ICON S r-- Microsoft Icon
IDENTITY P r-- Hald CLUT identity image
IMAGE P r-- GraphicsMagick Embedded Image
INFO S -w+ Image descriptive information and statistics
IPTC P rw- IPTC Newsphoto
IPTCTEXT P rw- IPTC Newsphoto text format
IPTCWTEXT P rw- IPTC Newsphoto text format
JNG P rw- JPEG Network Graphics (libpng 1.4.12, zlib 1.2.3)
See http://www.libpng.org/pub/mng/ for information on JNG.
JNX S r-- JNX: Garmin tile storage format
JPEG P rw- Joint Photographic Experts Group JFIF format (IJG JPEG 62)
JPG P rw- Joint Photographic Experts Group JFIF format (IJG JPEG 62)
K S rw+ Raw black samples
K25 S r-- Kodak Photo RAW
KDC S r-- Kodak Photo RAW
LABEL P r-- Image label
M S rw+ Raw magenta samples
M2V S -w+ MPEG Video Stream
MAC S r-- Mac Paint
MAP P rw- Colormap intensities and indices
MAT S rw+ MATLAB Level 4.0-7.0 image formats
MATTE S -w+ MATTE raw opacity format
MEF S r-- Mamiya Photo RAW
MIFF P rw+ Magick Image File Format
MNG P rw+ Multiple-image Network Graphics (libpng 1.4.12, zlib 1.2.3)
See http://www.libpng.org/pub/mng/ for information on MNG.
MONO S rw- Bi-level bitmap in least-significant-byte first order
MPC U rw+ Magick Persistent Cache image format
MPEG S -w+ MPEG Video Stream
MPG S -w+ MPEG Video Stream
MRW S r-- Minolta Photo RAW
MSL S rw+ Magick Scripting Language
MTV U rw+ MTV Raytracing image format
MVG S rw- Magick Vector Graphics
NEF S r-- Nikon Electronic Format
NULL P rw- Constant image of uniform color
O S rw+ Raw opacity samples
ORF S r-- Olympus Photo RAW
OTB S rw- On-the-air bitmap
P7 S rw+ Xv thumbnail format
PAL S rw- 16bit/pixel interleaved YUV
PALM U rw- Palm pixmap
PAM P rw+ Portable Arbitrary Map format
PBM P rw+ Portable bitmap format (black/white)
PCD S rw- Photo CD
PCDS S rw- Photo CD
PCL S -w+ Page Control Language
PCT S rw- Apple Macintosh QuickDraw/PICT
PCX S rw- ZSoft IBM PC Paintbrush
PDB S rw+ Palm Database ImageViewer Format
PDF P rw+ Portable Document Format
PEF S r-- Pentax Electronic File
PFA P r-- Postscript Type 1 font (ASCII)
PFB P r-- Postscript Type 1 font (binary)
PGM P rw+ Portable graymap format (gray scale)
PICON S rw- Personal Icon
PICT S rw- Apple Macintosh QuickDraw/PICT
PIX S r-- Alias/Wavefront RLE image format
PLASMA P r-- Plasma fractal image
PNG P rw- Portable Network Graphics (libpng 1.4.12, 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.4.12, zlib 1.2.3)
PNG24 P rw- 24-bit RGB PNG, opaque only (libpng 1.4.12, zlib 1.2.3)
PNG32 P rw- 32-bit RGBA PNG, semitransparency OK (libpng 1.4.12, zlib 1.2.3)
PNG48 P rw- opaque or binary transparent 48-bit RGB (libpng 1.4.12, zlib 1.2.3)
PNG64 P rw- opaque or transparent 64-bit RGBA (libpng 1.4.12, zlib 1.2.3)
PNG8 P rw- 8-bit indexed PNG, binary transparency only (libpng 1.4.12, zlib 1.2.3)
PNM P rw+ Portable anymap
PPM P rw+ Portable pixmap format (color)
PREVIEW S -w- Show a preview an image enhancement, effect, or f/x
PS P rw+ Adobe PostScript
PS2 P -w+ Adobe Level II PostScript
PS3 P -w+ Adobe Level III PostScript
PWP U r-- Seattle Film Works
R S rw+ Raw red samples
RAF S r-- Fuji Photo RAW
RAS S rw+ SUN Rasterfile
RGB S rw+ Raw red, green, and blue samples
RGBA S rw+ Raw red, green, blue, and matte samples
RLA U r-- Alias/Wavefront image
RLE S r-- Utah Run length encoded image
SCT U r-- Scitex HandShake
SFW U r-- Seattle Film Works
SGI S rw- Irix RGB image
SHTML P -w- Hypertext Markup Language and a client-side image map
SR2 S r-- Sony Photo RAW
SRF S r-- Sony Photo RAW
STEGANO P r-- Steganographic image
SUN S rw+ SUN Rasterfile
SVG S r-- Scalable Vector Graphics (XML 2.7.6)
SVGZ S r-- Scalable Vector Graphics (ZIP compressed) (XML 2.7.6)
TEXT S rw+ ASCII Text
TGA S rw+ Truevision Targa image
TILE P r-- Tile image with a texture
Use the syntax "-size WIDTHxHEIGHT TILE:imagename" to tile the
specified tile image over a canvas image of size WIDTHxHEIGHT.
TIM S r-- PSX TIM
TOPOL S r-- TOPOL X Image
TTF P r-- TrueType font
TXT S rw+ ASCII Text
UIL S -w- X-Motif UIL table
UYVY S rw- 16bit/pixel interleaved YUV
VDA S rw+ Truevision Targa image
VICAR S rw- VICAR rasterfile format
VID S rw+ Visual Image Directory
VIFF S rw+ Khoros Visualization image
VST S rw+ Truevision Targa image
WBMP S rw- Wireless Bitmap (level 0) image
WPG S r-- Word Perfect Graphics
X S rw- X Window System
X3F S r-- Foveon X3 (Sigma/Polaroid) RAW
XBM S rw- X Windows system bitmap (black/white)
XC P r-- Constant image uniform color
XCF S r-- GIMP image
XMP P rw- Adobe XML metadata
XPM S rw- X Windows system pixmap (color)
XV S rw+ Khoros Visualization image
XWD U rw- X Windows system window dump (color)
Y S rw+ Raw yellow samples
YUV S rw- CCIR 601 4:1:1 or 4:2:2 (8-bit only)
Meaning of 'L': P=Primary, S=Stable, U=Unstable
上传图片到/tmp目录下,使用gm vonvert 压缩图片
gm convert 原图 -thumbnail '100x100' 目标文件名
gm convert tt.jpg -thumbnail '100x100' output_xxx.jpg
将tt.jpg等比缩小到100x100大小。
更多命令格式:
GraphicsMagick常用方法
显示图像文件详细信息
identify a.jpg
2.更改当前目录下*.jpg的尺寸大小,并保存于目录.thumb里面
gm mogrify -output-directory .thumbs -resize 320×200 *.jpg
将三幅图像和并为一副图像
montage -mode concatenate -tile 3×1 image1.ppm image2.ppm image3.ppm concatenated.miff
显示图像
display ‘vid:*.jpg’
格式转换
convert a.bmp a.jpg
gm convert a.bmp a.pdf(转换为pdf)
调整图像dpi和大小
convert -density 288 -geometry 25% image.gif image.gif
(缩小为原先的1/4,并且dpi为288)
gm convert -resize 640×480 image.gif image.gif
(转换为640×480的图像)
在图像上添加文字
convert -font Arial -fill blue -pointsize 18 -draw “text 10,10 ‘your text here'” test.tif test.png
从gif文件中抽取第一帧
convert “Image.gif[0]” first.gif
建立gif图像
convert -delay 20 frame*.gif animation.gif
gm convert -loop 50 frame*.gif animation.gif
(让动画循环50次)
gm convert -delay 20 frame1.gif -delay 10 frame2.gif -delay 5 frame3.gif animation.gif
(对每一帧手动指定延时)
截屏
import a.jpg
用鼠标点击所要截取的窗口,或者选择截屏区域,保存为a.jpg
gm import -frame a.jpg
保留窗口的边框
Tag标签:「压缩 GraphicsMagick 图像 convert」更新时间:「2021-11-03 09:52:01」阅读次数:「1528」