ImageMagick学习

来源:互联网 发布:linux dma内存 编辑:程序博客网 时间:2024/05/03 17:18

原贴地址:http://hedong.3322.org/archives/000339.html 

ImageMagick是一套稳定的工具集和开发包,可以用来读、写和处理超过89种基本格式的图片文件,包括流行的TIFF, JPEG, GIF, PNG, PDF以及PhotoCD等格式。利用ImageMagick,你可以根据web应用程序的需要动态生成图片, 还可以对一个图片或图片序列进行改变大小、旋转、锐化、减色或增加特效,并将操作的结果以相同格式或其它格式保存。对图片的操作,可以通过命令行进行,也可以用C/C++、Perl、Java、PHP、Python或Ruby编程来完成。同时ImageMagick提供了一个高质量的2D工具包,部分地支持SVG。现在,ImageMagic的主要精力集中在性能、减少bug以及提供稳定的API和ABI上。
  ImageMagick功能强大,却免费的。

 

ImageMagick的功能

包括:

  1. 将图片从一个格式转换到另一个格式
  2. 改变尺寸、旋转、锐化(sharpen)、减色、图片特效
  3. 缩略图片的合成图( a montage of image thumbnails)
  4. 适于web的背景透明的图片
  5. 将一组图片做成gif动画
  6. 将几张图片做成一张组合图片
  7. 在一个图片上写字或画图形
  8. 给图片加边框或框架
  9. 取得一些图片的特性信息

        右面是一些例子。


        ImageMagick几乎可以在任何非专有的操作系统上编译,无论是32位还是64位的CPU,包括*nix ,Windows '95/'98/ME/NT 4.0/2000/XP, Macintosh (MacOS 9 /10), VMS 和 OS/2.

      下载安装

        ImageMagick在很多服务器上都可以下到,甚至很多个人站点也提供了下载。建议到ImageMagick的官方主页上下载最新版本的源码包,我下的是ImageMagick-5.5.6.tar.gz,在linux下的安装过程如下:
      tar zxvf ImageMagick-5.5.6.tar.gz
      cd ImageMagick-5.5.6
      ./configure
      make all
      su
      make install


        注意不要忘记,将ImageMagick安装后的函数库所在目录加入到/etc/profile文件中的LD_LIBRARY_PATH环境变量中,以及/etc/ld.so.conf中同时运行ldconfig,否则一些对ImageMagic的应用可能会出问题。

      使用说明

命令行工具说明


程序名命令行参数说明animate[ options ... ] file [ [ options ... ] file ... ]显示一个图片序列。为防止颜色闪烁,它会费时为图片序列创建一个颜色表,这可通过减色来加快速度,参见 http://www.wizards.dupont.com/cristy/www/animate.html。composite[ options ... ] image composite [ mask ] composited将图片合成为新图片。conjure[ options ] script.msl [ [ options ] script.msl ]解释并执行Magick Scripting Language (MSL).语言脚本。convert[ [ options ... ] [ input_file ... ] ... [ output_file ] ]转换图片的大小、格式等。display[ options ... ] file ... [ [options ... ]file ... ]一个独立于机器框架的图片处理和显示程序,能在任何运行X服务器的工作站上显示图片。identifyfile [ file ... ]描述一张或一些图片的格式或个性信息,如果图片不完整或被破坏也会有相应报告。import[ options ... ] file读取X服务器上任何可见窗口中的图象将输出为图片文件。可以用它抓取一个窗口、整个屏幕或屏幕上的任何矩形区域。mogrify[ options ... ] file ...转换一张图片或一个图片序列. 包括图片缩放、旋转、减色及其它操作。转换结果覆盖原图片。  ImageMagick支持的某些文件格式,需要安装特别的函数库,具体参见http://www.imagemagick.org/www/install.html。用convert -list format 可以看一下实际支持的文件格式。

 

  http://www.imagemagick.org/www/utilities.html 有对命令行参数的详细说明,http://www-106.ibm.com/developerworks/library/l-graf/?ca=dnt-428有一些使用例程。http://www.starlink.rl.ac.uk/star/docs/sc15.htx/node57.html有一些说明。

  ImageMagick还支持一种平台无关的文件格式Magick Image File Format (MIFF)格式,用来保存bitmap图片.ImageMagick能将MIFF与JPEG, XPM, TIFF等多种格式的图片互相转换。
附:ImageMagick支持图片格式、内建图片和图片模板以及嵌入图片模板。

Supported ImageFormats


Format

Mode

Description

NotesARTRPFS:1st PublisherFormatoriginally used on the Macintosh (MacPaint?) and later used forPFS: 1st Publisher clip art.

AVI

RMicrosoftAudio/Visual Interleaved AVSRWAVS Ximage 

BMP

RWMicrosoftWindows bitmap CGMRComputerGraphics MetafileRequiresralcgm torender CGM files.

CIN

RWKodakCineon Image Format

Cineon Image Format is a subset of SMTPE DPX.

CMYKRWRawcyan, magenta, yellow, and black samplesSet-size and-depth to specify theimage width, height, and depth.CURRMicrosoftCursor Icon CUTRDR Halo DCMRDigitalImaging and Communications in Medicine (DICOM) imageUsedby the medical community for images like X-rays.DCXRWZSoftIBM PC multi-page Paintbrush image DIBRWMicrosoftWindows Device Independent BitmapDIB is aBMP file without theBMP header. Used to support embedded images incompound formats like WMF.DPXRWDigitalMoving Picture Exchange EMFRMicrosoftEnhanced Metafile (32-bit)Onlyavailable under Microsoft Windows.EPDFRWEncapsulatedPortable Document Format EPIRWAdobeEncapsulated PostScript Interchange formatRequiresGhostscriptto read.EPSRWAdobeEncapsulated PostScriptRequiresGhostscriptto read.EPS2WAdobeLevel II Encapsulated PostScriptRequiresGhostscriptto read.EPS3WAdobeLevel III Encapsulated PostScriptRequiresGhostscriptto read.EPSFRWAdobeEncapsulated PostScriptRequiresGhostscriptto read.EPSIRWAdobeEncapsulated PostScript Interchange formatRequiresGhostscriptto read.EPTRWAdobe Encapsulated PostScript Interchange format withTIFF previewRequiresGhostscriptto read.FAXRWGroup3 TIFFSeeTIFF format. Note that FAXmachines use non-square pixels which are 1.5 times wider than theyare tall but computer displays use square pixels so FAX images mayappear to be narrow unless they are explicitly resized using aresize specification of "150x100%".

FIG

RFIGgraphics formatRequiresTransFig.

FITS

RWFlexibleImage Transport System FPXRWFlashPixFormatRequiresFlashPixSDK.GIFRWCompuServeGraphics Interchange Format8-bitRGB PseudoColor with up to 256 palette entires. Specify theformat "GIF87" to write the older version 87a of the format.Note that since Unisys claims apatent onthe LZW algorithm (expiring world-wide as of June 2004) used byGIF, ImageMagick binary distributions do not include support forthe LZW algorithm so GIF files are written uncompressed. Users arerecommended to use the PNG or JPEG formats instead, and shouldconsult theUnisysLZW web page before enabling LZW support.GPLTRGnuplotplot filesRequiresgnuplot3.5.tar.Zor later.GRAYRWRawgray samplesUse-size and-depth to specify theimage width, height, and depth.HPGLRHP-GLplotter languageRequireshp2xx-3.2.0.tar.gzHTMLRWHypertextMarkup Language with a client-side image mapAlso known as "HTM". Requireshtml2ps to read.ICORMicrosofticonAlsoknown as "ICON".JBIGRWJointBi-level Image experts Group file interchange formatAlso known as "BIE" and "JBG". Requiresjbigkit-1.0.tar.gz.

JNG

RWMultiple-imageNetwork GraphicsJPEG in a PNG-style wrapper with transparency. Requireslibjpeg and libpng-1.0.2 or later,libpng-1.2.5or later recommended.JP2RWJPEG-2000JP2 File Format SyntaxRequiresjasper-1.600.0.zipJPCRWJPEG-2000Code Stream SyntaxRequiresjasper-1.600.0.zipJPEGRWJointPhotographic Experts Group JFIF formatRequiresjpegsrc.v6b.tar.gzMANRUnixreference manual pagesRequiresthat GNU groff and Ghostcript are installed.MATRMATLABimage format 

MIFF

RWMagickimage file formatOpenImageMagick's own image format (with ASCII header) which ensuresthat no image attributes understood by ImageMagick are lost.MONORWBi-levelbitmap in least-significant-byte first order 

MNG

RWJPEGNetwork GraphicsRequires libpng-1.0.2 or later,libpng-1.2.5or later recommended.

MPEG

RWMotionPicture Experts Group file interchange format (version 1)Requiresmpeg2vidcodec_v12.tar.gz.

M2V

RWMotionPicture Experts Group file interchange format (version 2)Requiresmpeg2vidcodec_v12.tar.gz.MPCRWMagickPersistent Cache image file formatThenative "in-memory" ImageMagick uncompressed file format. Thisfile format is identical to that used by Open ImageMagick torepresent images in memory and is read in "zero time" via memorymapping. The MPC format is not portable and is not suitable as anarchive format. It is suitable as an intermediate format forhigh-performance image processing.TheMPC format requires two files to support one image. When writingthe MPC format, a file with extension ".mpc" is used to storeinformation about the image, while a file with extension “.cache”stores the image pixels. The storage space required by a MPC image(or an image in memory) may be calculated by the equation(QuantumDepth*Rows*Columns*5)/8.MSLRWMagickScripting LanguageMSL is the XML-based scripting language supported by the conjure utility.MTVRWMTVRaytracing image format MVGRWMagickVector Graphics.The native ImageMagick vector metafile format. A textfile containing vector drawing commands accepted by convert's -draw option.OTBRWOn-the-airBitmap P7RWXv'sVisual Schnauzer thumbnail format PALMRWPalmpixmap PBMRWPortablebitmap format (black and white) PCDRWPhotoCDThemaximum resolution written is 768x512 pixels since larger imagesrequire huffman compression (which is not supported).PCDSRWPhotoCDDecodewith the sRGB color tables.PCLWHPPage Control LanguageForoutput to HP laser printers.PCXRWZSoftIBM PC Paintbrush file PDBRWPalmDatabase ImageViewer Format PDFRWPortableDocument FormatRequiresGhostscriptto read.PFARPostscriptType 1 font (ASCII)Openingas file returns a preview image.PFBRPostscriptType 1 font (binary)Openingas file returns a preview image.PGMRWPortablegraymap format (gray scale) PICONRWPersonalIcon PICTRWAppleMacintosh QuickDraw/PICT file PIXRAlias/WavefrontRLE image format 

PNG

RWPortableNetwork GraphicsRequires libpng-1.0.2 or later,libpng-1.2.5or later recommended.PNMRWPortableanymapPNM isa family of formats supporting portable bitmaps (PBM) , graymaps(PGM), and pixmaps (PPM). There is no file format associated withpnm itself. If PNM is used as the output format specifier, thenImageMagick automatically selects the most appropriate format torepresent the image.The default is to write the binary version of theformats. Use+compress to write the ASCII version of theformats.PPMRWPortablepixmap format (color) PSRWAdobePostScript fileRequiresGhostscriptto read.PS2RWAdobeLevel II PostScript fileRequiresGhostscriptto read.PS3RWAdobeLevel III PostScript fileRequiresGhostscriptto read.PSDRWAdobePhotoshop bitmap file PTIFRWPyramid encodedTIFFMulti-resolutionTIFF containingsuccessively smaller versions of the image down to the size of anicon. The desired sub-image size may be specified when reading viathe -size option.

PWP

RSeattleFile Works multi-image file RADRRadianceimage fileRequiresthatra_ppm from the Radiance software package beinstalled.RGBRWRawred, green, and blue samplesUse-size and-depth to specify theimage width, height, and depth.RGBARWRawred, green, blue, and matte samplesUse-size and-depth to specify theimage width, height, and depth.RLARAlias/Wavefrontimage file RLERUtahRun length encoded image file 

SCT

RScitexContinuous Tone Picture 

SFW

RSeattleFile Works image SGIRWIrixRGB image SHTMLWHypertextMarkup Language client-side image mapUsed to write HTML clickable image maps based on a theoutput of montage or a format whichsupports tiled images such as MIFF.SUNRWSUNRasterfile 

SVG

RWScalableVector GraphicsRequireslibxml2 andfreetype-2. Note that SVG is avery complex specification so support is still not complete.TGARWTruevisionTarga imageAlsoknown as formats "ICB", "VDA", and "VST".TIFFRWTaggedImage File FormatAlso known as "TIF". Requirestiff-v3.5.4.tar.gzor later. Note that since Unisys claims apatent onthe LZW algorithm (expiring in the US as of June 2003) used byLZW-compressed TIFF files, ImageMagick binary distributions do notinclude support for the LZW algorithm so LZW TIFF files can not bewritten. Although a patch is available for libtiff to enablebuilding with LZW support. Users should consult theUnisys LZW web pagebefore applying it.TIMRPSXTIM file 

TTF

RTrueTypefont fileRequiresfreetype 2.Opening as file returns a preview image.TXTRWRawtext file UILWX-MotifUIL table UYVYRWInterleavedYUV raw imageUse-size command line option to specify widthand height.VICARRWVICARrasterfile format VIFFRWKhorosVisualization Image File Format 

WBMP

RWWirelessbitmapSupportfor uncompressed monochrome only.

WMF

 WindowsMetafileRequireslibwmf.By default, renders WMF files using the dimensions specified by themetafile header. Use the -density option to adjust the outputresolution, and thereby adjust the ouput size. The default outputresolution is 72DPI so "-density 144" results in an image twiceas large as the default. Use-background color tospecify the WMF background color (default white) or-texturefilename to specify a background texture image.WPGRWordPerfect Graphics File XBMRWXWindows system bitmap, black and white onlyUsedby the X Windows System to store monochrome icons.XCFRGIMPimage 

XPM

RWXWindows system pixmapAlsoknown as "PM". Used by the X Windows System to store color icons.XWDRWXWindows system window dumpUsedby the X Windows System to save/display screen dumps.YUVRWCCIR601 4:1:1Use-size command line option to specify widthand height.

Pseudo ImageFormats


TagModeDescriptionNotes

CAPTION

RImagecaptionfixmeCLIPBOARDRWWindowsClipboardOnlyavailable under Microsoft Windows.FRACTALRPlasmafractal image

 

GRADIENTRGradualpassing from one shade to anotherReturns a rendered gradient image using the specifiedimage size. Specify the desired shading as part of the filename(e.g. "gradient:red-blue"or "gradient:#F00-#00F").HISTOGRAMWHistogramof the image

 

LABELRTextimage formatSpecify the desired text as the filename (e.g. "label:Thisis a label").MAPRWColormapintensities and indicesSet-depth to set the sample size of the intensities; indices are16-bit if colors > 256.MATTEWMATTEformatWriteonly.NULLRWNULLimageUseful for creating blank tiles with montage (use "NULL:"). Also useful as anoutput format when evaluating image read performance.PLASMARPlasmafractal image

 

PREVIEWWShow apreview an image enhancement, effect, or f/xCreates a preview montage of images prepared over aparameteric range in order to assist with parameter selection.Specify the desired preview type via the-preview option).PRINTWSendimage to your computer printerUnixusers may set the PRINTER (for 'lp') or LPDEST (for 'lpr')environment variables to select the desired printer.SCANRImportimage from a scanner deviceRequires SANESpecify the device name and path as the filename (e.g. "scan:mustek:/dev/scanner").STEGANORSteganographicimageUse -size command line option to specify width,height, and offset of the steganographic imageTILERTiledimageCreatea tiled version of an image at by tiling a image. Use -size tospecify the tiled image size. The image is specified similar to "TILE:image.miff".VIDRWVisualImage DirectoryUsed to create a thumbnailed directory (tiled thumbnails)of a set of images which may be used to select images to view viathe display program, or saved to a MIFF orSHTML file.WINRWSelectimage from or display image to your computer screenOnlysupported under Microsoft Windows.XRWSelectimage from or display image to your X server screenAlso see the import and display programs.XCRCanvasimage of specified colorUseful to create solid color "canvas" images. Use -sizeand -depth to specify the image width, height, anddepth. Example XC color specifications include "XC:red" and "XC:#FF0000".

Built-in Image Formats

NameDescriptionNotes/SampleGRANITE128x128granite texture patternLOGO640x480,ImageMagick LogoNETSCAPE216x144image using colors in Netscape 216 (6x6x6 ) color cube.

Most commonly used with the convert/mogrify -map option to create “web safe”images.

ROSE70x46,Picture of a rose.

Built-inImage Patterns

NameDescriptionNotes/SampleBRICKS16x16brick patternCHECKERBOARD30x30checkerboard patternCIRCLES16x16circles patternCROSSHATCH8x4crosshatch patternCROSSHATCH308x4crosshatch pattern with lines at 30 degrees.CROSSHATCH458x4crosshatch pattern with lines at 45 degrees.FISHSCALES16x8fish scales patternGRAY032x320% intensity grayGRAY532x325% intensity grayGRAY1032x3210% intensity grayGRAY1532x3215% intensity grayGRAY2032x3220% intensity grayGRAY2532x3225% intensity grayGRAY3032x3230% intensity grayGRAY3532x3235% intensity grayGRAY4032x3240% intensity grayGRAY4532x3245% intensity grayGRAY5032x3250% intensity grayGRAY5532x3255% intensity grayGRAY6032x3260% intensity grayGRAY6532x3265% intensity grayGRAY7032x3270% intensity grayGRAY7532x3275% intensity grayGRAY8032x3280% intensity grayGRAY8532x3285% intensity grayGRAY9032x3290% intensity grayGRAY9532x3295% intensity grayGRAY10032x32100% intensity grayHEXAGONS30x18hexagon patternHORIZONTAL8x4horizontal line patternHORIZONTALSAW16x8horizontal saw-tooth patternHS_BDIAGONAL8x8backward diagonal line pattern (45 degrees slope)HS_CROSS8x8cross line patternHS_DIAGCROSS8x8diagonal line cross pattern (45 degrees slope)HS_FDIAGONAL8x8forward diagonal line pattern (45 degrees slope)HS_HORIZONTAL8x8horizontal line patternHS_VERTICAL8x8vertical line patternLEFT308x4forward diagonal pattern (30 degrees slope)LEFT458x8forward diagonal line pattern (45 degrees slope)LEFTSHINGLE24x24left shingle patternOCTAGONS16x16octagons pattern

RIGHT308x4backward diagonal line pattern (30 degrees)

RIGHT458x8backward diagonal line pattern (30 degrees)

RIGHTSHINGLE24x24right shingle pattern

SMALLFISHSCALES8x8small fish scales patternVERTICAL8x8vertical line patternVERTICALBRICKS16x16vertical brick patternVERTICALLEFTSHINGLE24x24vertical left shingle patternVERTICALRIGHTSHINGLE24x24vertical right shingle patternVERTICALSAW8x16vertical saw-tooth pattern
EmbeddedImage Patterns
FormatModeDescriptionNotes8BIMRWPhotoshopresource format (binary)

 

8BIMTEXTRWPhotoshopresource format (ASCII)AnASCII representation of the 8BIM format.APP1RWRawapplication information

 

APP1JPEGRWRawJPEG binary dataProfilein JPEG wrapper.ICCRWInternationalColor Consortium color profile

Also known as "ICM". To read, use-profile withconvert.

IPTCRWIPTCNewsphoto (binary)

To read, use -profile withconvert

IPTCTEXTRWIPTCNewsphoto (ASCII)AnASCII representation of the IPTC format.

 

Posted by Hilton at October 28, 2003 09:34 PM |TrackBack
Comments

你好。我也对ImageMagick感兴趣。
你能否说明一下如何在perl下调用其内置图片。

在perl下的demo中,有关于logo的调用。
但是,现在我使用rose,就没有图片生成。

测试环境:ImageMagick5.3.1 ~5.5.7

谢谢。

Posted by: fengme at February 4, 2004 05:45 PM

http://www.infomall.cn/cgi-bin/mallgate/20040514/http://www.imagemagick.org/www/Magick++/STL.html
这个页面中有一个东东能加水印到一个图片上,是这样说的:
steganoImage const Image &watermark_ Add a digital watermark to the image (based on second image)
可是我实在不知道怎么弄?
里面有这样一段
#include
#include
using namespace std;
using namespace Magick;

int main(int /*argc*/,char **/*argv*/)
{
list imageList;
readImages( &imageList, "test_image_anim.gif" );

Image appended;
appendImages( &appended, imageList.begin(), imageList.end() );
appended.write( "appended_image.miff" );
return 0;
}
我在jsp里怎么弄呢?


原创粉丝点击