`
yzgfbj
  • 浏览: 77399 次
  • 来自: ...
社区版块
存档分类
最新评论

ImageMagick处理图片是使用Msl(问题补充)

阅读更多
在使用外部msl配置生成图片后,发现原有的配置方式,当大图处理小图时,没有问题。当传入的图片尺寸小于要格式化的尺寸时,由于配置文件不知道,会强制resize,将小图拉伸影响效果。
<?xml version="1.0" encoding="UTF-8"?>	
<image>	    
	    <read filename="test.jpg" />	   
		  <resize geometry="200x200" />	
	    <write filename="test_200.jpg" />
</image>

如上示例,当test.jpg的尺寸大于200x200时,没有问题,会生成200x200的小图test_200.jpg。当时当test.jpg的尺寸小于200x200时,通过配置文件生成会强制拉伸到200x200的图片,而实际使用中一般当小于要处理的尺寸时,应该不处理。
查了imageMagick的convert -resize的说明有如下的内容:
-resize widthxheight{%} {@} {!} {<} {>} {^}
Use > to change the dimensions of the image only if its width or height exceeds the geometry specification. < resizes the image only if both of its dimensions are less than the geometry specification. For example, if you specify 640x480> and the image size is 256x256, the image size does not change. However, if the image is 512x512 or 1024x1024, it is resized to 480x480. Enclose the geometry specification in quotation marks to prevent the < or > from being interpreted by your shell as a file redirection.
大概意思就是说用了> < 号,对于实际的尺寸会有一些影响。
为了测试是否正确,就在cmd命令行下试验
convert -resize 200x200> test.jpg test_200.jpg

报错:convert: missing an image filename `test_200.jpg'.
奇怪让生成test_200.jpg,竟然报找不到文件。
通过多次的实验发现有可能是windows重定向>的问题。
实验:
convert -resize >200x200 test.jpg test_200.jpg

报错:convert: invalid argument for option `test.jpg': -resize.
包参数错误,但是看文件夹生成了200x200的一个文件,大小为空,说明windows重定向起了作用。
一时不知怎么解决,旁边的搭档提醒,在msl文件里直接加试一下(200x200>)
<?xml version="1.0" encoding="UTF-8"?>	
<image>	    
	    <read filename="test.jpg" />	   
	    <resize geometry="200x200>" />	
	    <write filename="test_200.jpg" />
</image>

在配置文件的相应参数处加了处理符号,运行。
conjure test.msl

查看运行目录,一切正常,用尺寸小于200的文件测试,没有问题,一切正常。看来真是windows命令解析出了问题,用配置文件,可能自己内部处理,反而没有了问题。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics