用ImageMagick批量转换图片格式【部分转载】

介绍如何使用ImageMagick将PNG和JPG格式的图片批量转换为EPS格式,并提供了一个批处理脚本示例。同时介绍了不同PostScript级别(Level1至Level3)的特点及其对文件大小的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[size=large]写Latex时经常要将png、jpg文件转为eps的,每次都用photoshop或者matlab很麻烦,,,,发现ImageMagick还不错~[/size]
[color=blue][size=x-large]1、下载[/size][/color]
[size=large]到下列网址下载了安装即可[/size]
[url]http://www.imagemagick.org/script/binary-releases.php#windows[/url]
[size=large]支持的文件格式:[/size][url]http://www.imagemagick.org/script/formats.php[/url]

[color=blue][size=x-large]2、eps文件的处理[/size][/color]
[size=large]据说需要安装GhostScript,没测试,反正CTex中带有GhostScript。[/size]

[color=blue][size=x-large]3、写好的批处理文件[/size][/color]
[size=large]下列代码用于将当前目录的jpg、png文件转换为eps文件,注意是eps3的,据说转换后文件比较小,实际真的比较小,500k对比30M啊!!!兼容性不知道。。。反正我的CTex用着没问题。
图片大小设为高度或宽度均得小于1600像素(数值随便设的,否则大图片显示不全啊!!)[/size]

for %%I in (*.jpg) do convert -resize "1600x1600>" %%I  eps3:%%~nI.eps
for %%I in (*.png) do convert -resize "1600x1600>" %%I eps3:%%~nI.eps


[color=blue][size=x-large]4、输出图片大小有关的选项[/size][/color]
参见:[url]http://www.imagemagick.org/script/command-line-processing.php#geometry[/url]
[size=large]除了下列选项外,貌似 [color=blue]-page[/color]选项也比较有用,没测试[/size]
[img]http://dl.iteye.com/upload/attachment/0076/6819/fe457e5e-40c5-37c0-989d-10973ab6828c.png[/img]


[color=blue][size=x-large]附录:参考及转载[/size][/color]

[color=red][size=large]convert的更多有用选项:[/size][/color]
转载自:[url]http://blog.sina.com.cn/s/blog_44a0dd4c0100cqq8.html[/url]
[quote]convert.exe
最简单的用法:convert.exe aaa.jpg aaa.png
可能用到的参数(没用到的我就不解释了,是在太多):
-layers flatten:在转换psd文件的时候用于合并多图层为一个图层,否则的话转换多图层的psd图就会出现多张图,每张图对应一个图层。
例如:convert.exe -layers flatten aaa.psd aaa.jpg
-density 72:指定图片的解析度,也就是单位面积像素数,不知道这样理解对不对,默认的单位是inch。
-units PixelsPerInch:指定单位,这个配合-density使用,指定-density的单位,这个很重要啊,我发现有些图片的解析度单位是centimeter,这两个单位差得还是比较远的。
例如:convert.exe -density 72 -units PixelsPerInch aaa.tif aaa.jpg
-resize 1024x768:指定图片转换的大小。IM会自动判断图片的宽和高进行等比压缩。但是这会有个问题,就是当图片小于1024x768时会将图片强制放大。可以在1024x768后面加上'>','<'等限定符来限制转换行为。1024x768>是只转换大于1024x768的图,1024x768<只转换小于1024x768的图。其他限定符请参考手册。
例如:convert.exe -resize "1024x768>" aaa.tif aaa.jpg
注意:1024x768>要用引号扩起来,否则'>'会被系统解释为输出重定向。
-filter Lanczos:指定转换图片时的过滤器,通常配合-resize使用。有很多种过滤器,挨个试了之后觉得这个合适,其他的也不懂。
-quality 100:指定jpeg的图片质量压缩比。默认是80%,我这里指定100%,最佳质量。
-colorspace rgb:指定转换后图片的色彩空间。有很多种色彩空间,PC上使用rgb足矣。
+profile "*":删除图片附带的元数据信息,包括exif等等。这些数据很占空间的,所以直接删除。

idenfify.exe
这个工具用来查看图片的详细信息,包括色彩空间,图层信息等等。
查看图片的更多详细信息使用:identify.exe -verbose aaa.jpg

有了以上的参数,基本上能够搞定一切了。但是要让ImageMagick处理eps的图像文件,还需要安装另外一个软件包GhostScript,专门用来处理ps文件的,搜索一下下载就可以。[/quote]


[color=red][size=large]关于eps3选项用法转载自:[/size][/color][url]http://blog.sciencenet.cn/home.php?mod=space&uid=47991&do=blog&id=535301[/url]
[quote]convert fig.png eps3:fig.eps
这里的eps3表示用Level 3,Level指的是postscript所采用的compatibility level。Level 1效果最差而且文件很大,Level 2支持从jpg产生eps文件,产生的文件也很小。Level 3包含了对Zlib压缩的支持,也可以从png产生eps文件。通常来说,Level 3产生的文件最小,Level 2兼容性最好。[/quote]
Version: ImageMagick 6.7.6-7 2012-04-20 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC Features: OpenMP Usage: convert.exe [options ...] file [ [options ...] file ...] [options ...] file Image Settings: -adjoin join images into a single multi-image file -affine matrix affine transform matrix -alpha option activate, deactivate, reset, or set the alpha channel -antialias remove pixel-aliasing -authenticate password decipher image with this password -attenuate value lessen (or intensify) when adding noise to an image -background color background color -bias value add bias when convolving an image -black-point-compensation use black point compensation -blue-primary point chromaticity blue primary point -bordercolor color border color -caption string assign a caption to an image -channel type apply option to select image channels -colors value preferred number of colors in the image -colorspace type alternate image colorspace -comment string annotate image with comment -compose operator set image composite operator -compress type type of pixel compression when writing the image -define format:option define one or more image format options -delay value display the next image after pausing -density geometry horizontal and vertical density of the image -depth value image depth -direction type render text right-to-left or left-to-right -display server get image or font from this X server -dispose method layer disposal method -dither method apply error diffusion to image -encoding type text encoding type -endian type endianness (MSB or LSB) of the image -family name render text with this font family -fill color color to use when filling a graphic primitive -filter type use this filter when resizing an image -font name render text with this font -format "string" output formatted image characteristics -fuzz distance colors within this distance are considered equal -gravity type horizontal and vertical text placement -green-primary point chromaticity green primary point -intent type type of rendering intent when managing the image color -interlace type type of image interlacing scheme -interline-spacing value set the space between two text lines -interpolate method pixel color interpolation method -interword-spacing value set the space between two words -kerning value set the space between two letters -label string assign a label to an image -limit type value pixel cache resource limit -loop iterations add Netscape loop extension to your GIF animation -mask filename associate a mask with the image -mattecolor color frame color -monitor monitor progress -orient type image orientation -page geometry size and location of an image canvas (setting) -ping efficiently determine image attributes -pointsize value font point size -precision value maximum number of significant digits to print -preview type image preview type -quality value JPEG/MIFF/PNG compression level -quiet suppress all warning messages -red-primary point chromaticity red primary point -regard-warnings pay attention to warning messages -remap filename transform image colors to match this set of colors -respect-parentheses settings remain in effect until parenthesis boundary -sampling-factor geometry horizontal and vertical sampling factor -scene value image scene number -seed value seed a new sequence of pseudo-random numbers -size geometry width and height of image -stretch type render text with this font stretch -stroke color graphic primitive stroke color -strokewidth value graphic primitive stroke width -style type render text with this font style -synchronize synchronize image to storage device -taint declare the image as modified -texture filename name of texture to tile onto the image background -tile-offset geometry tile offset -treedepth value color tree depth -transparent-color color transparent color -undercolor color annotation bounding box color -units type the units of image resolution -verbose print detailed information about the image -view FlashPix viewing transforms -virtual-pixel method virtual pixel access method -weight type render text with this font weight -white-point point chromaticity white point Image Operators: -adaptive-blur geometry adaptively blur pixels; decrease effect near edges -adaptive-resize geometry adaptively resize image using 'mesh' interpolation -adaptive-sharpen geometry adaptively sharpen pixels; increase effect near edges -alpha option on, activate, off, deactivate, set, opaque, copy transparent, extract, background, or shape -annotate geometry text annotate the image with text -auto-gamma automagically adjust gamma level of image -auto-level automagically adjust color levels of image -auto-orient automagically orient (rotate) image -bench iterations measure performance -black-threshold value force all pixels below the threshold into black -blue-shift factor simulate a scene at nighttime in the moonlight -blur geometry reduce image noise and reduce detail levels -border geometry surround image with a border of color -bordercolor color border color -brightness-contrast geometry improve brightness / contrast of the image -cdl filename color correct with a color decision list -charcoal radius simulate a charcoal drawing -chop geometry remove pixels from the image interior -clamp restrict pixel range from 0 to the quantum depth -clip clip along the first path from the 8BIM profile -clip-mask filename associate a clip mask with the image -clip-path id clip along a named path from the 8BIM profile -colorize value colorize the image with the fill color -color-matrix matrix apply color correction to the image -contrast enhance or reduce the image contrast -contrast-stretch geometry improve contrast by `stretching' the intensity range -convolve coefficients apply a convolution kernel to the image -cycle amount cycle the image colormap -decipher filename convert cipher pixels to plain pixels -deskew threshold straighten an image -despeckle reduce the speckles within an image -distort method args distort images according to given method ad args -draw string annotate the image with a graphic primitive -edge radius apply a filter to detect edges in the image -encipher filename convert plain pixels to cipher pixels -emboss radius emboss an image -enhance apply a digital filter to enhance a noisy image -equalize perform histogram equalization to an image -evaluate operator value evaluate an arithmetic, relational, or logical expression -extent geometry set the image size -extract geometry extract area from image -fft implements the discrete Fourier transform (DFT) -flip flip image vertically -floodfill geometry color floodfill the image with color -flop flop image horizontally -frame geometry surround image with an ornamental border -function name parameters apply function over image values -gamma value level of gamma correction -gaussian-blur geometry reduce image noise and reduce detail levels -geometry geometry preferred size or location of the image -identify identify the format and characteristics of the image -ift implements the inverse discrete Fourier transform (DFT) -implode amount implode image pixels about the center -lat geometry local adaptive thresholding -layers method optimize, merge, or compare image layers -level value adjust the level of image contrast -level-colors color,color level image with the given colors -linear-stretch geometry improve contrast by `stretching with saturation' -liquid-rescale geometry rescale image with seam-carving -median geometry apply a median filter to the image -mode geometry make each pixel the 'predominant color' of the neighborhood -modulate value vary the brightness, saturation, and hue -monochrome transform image to black and white -morphology method kernel apply a morphology method to the image -motion-blur geometry simulate motion blur -negate replace every pixel with its complementary color -noise geometry add or reduce noise in an image -normalize transform image to span the full range of colors -opaque color change this color to the fill color -ordered-dither NxN add a noise pattern to the image with specific amplitudes -paint radius simulate an oil painting -polaroid angle simulate a Polaroid picture -posterize levels reduce the image to a limited number of color levels -profile filename add, delete, or apply an image profile -quantize colorspace reduce colors in this colorspace -radial-blur angle radial blur the image -raise value lighten/darken image edges to create a 3-D effect -random-threshold low,high random threshold the image -region geometry apply options to a portion of the image -render render vector graphics -repage geometry size and location of an image canvas -resample geometry change the resolution of an image -resize geometry resize the image -roll geometry roll an image vertically or horizontally -rotate degrees apply Paeth rotation to the image -sample geometry scale image with pixel sampling -scale geometry scale the image -segment values segment an image -selective-blur geometry selectively blur pixels within a contrast threshold -sepia-tone threshold simulate a sepia-toned photo -set property value set an image property -shade degrees shade the image using a distant light source -shadow geometry simulate an image shadow -sharpen geometry sharpen the image -shave geometry shave pixels from the image edges -shear geometry slide one edge of the image along the X or Y axis -sigmoidal-contrast geometry increase the contrast without saturating highlights or shadows -sketch geometry simulate a pencil sketch -solarize threshold negate all pixels above the threshold level -sparse-color method args fill in a image based on a few color points -splice geometry splice the background color into the image -spread radius displace image pixels by a random amount -statistic type geometry replace each pixel with corresponding statistic from the neighborhood -strip strip image of all profiles and comments -swirl degrees swirl image pixels about the center -threshold value threshold the image -thumbnail geometry create a thumbnail of the image -tile filename tile image when filling a graphic primitive -tint value tint the image with the fill color -transform affine transform image -transparent color make this color transparent within the image -transpose flip image vertically and rotate 90 degrees -transverse flop image horizontally and rotate 270 degrees -trim trim image edges -type type image type -unique-colors discard all but one of any pixel color -unsharp geometry sharpen the image -vignette geometry soften the edges of the image in vignette style -wave geometry alter an image along a sine wave -white-threshold value force all pixels above the threshold into white Image Sequence Operators: -append append an image sequence -clut apply a color lookup table to the image -coalesce merge a sequence of images -combine combine a sequence of images -composite composite image -crop geometry cut out a rectangular region of the image -deconstruct break down an image sequence into constituent parts -evaluate-sequence operator evaluate an arithmetic, relational, or logical expression -flatten flatten a sequence of images -fx expression apply mathematical expression to an image channel(s) -hald-clut apply a Hald color lookup table to the image -morph value morph an image sequence -mosaic create a mosaic from an image sequence -print string interpret string and print to console -process arguments process the image with a custom image filter -separate separate an image channel into a grayscale image -smush geometry smush an image sequence together -write filename write images to this file Image Stack Operators: -clone indexes clone an image -delete indexes delete the image from the image sequence -duplicate count,indexes duplicate an image one or more times -insert index insert last image into the image sequence -reverse reverse image sequence -swap indexes swap two images in the image sequence Miscellaneous Options: -debug events display copious debugging information -help print program options -list type print a list of supported option arguments -log format format of debugging information -version print version information By default, the image format of `file' is determined by its magic number. To specify a particular image format, precede the filename with an image format name and a colon (i.e. ps:image) or specify the image type as the filename suffix (i.e. image.ps). Specify 'file' as '-' for standard input or output.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值