0

ImageMagick 文档说以下是有效的图像几何参数形式:

size    General description (actual behavior can vary for different options and settings)
scale%  Height and width both scaled by specified percentage.
scale-x%xscale-y%   Height and width individually scaled by specified percentages. (Only one % symbol needed.)
width   Width given, height automagically selected to preserve aspect ratio.
xheight Height given, width automagically selected to preserve aspect ratio.
widthxheight    Maximum values of height and width given, aspect ratio preserved.
widthxheight^   Minimum values of width and height given, aspect ratio preserved.
widthxheight!   Width and height emphatically given, original aspect ratio ignored.
widthxheight>   Shrinks an image with dimension(s) larger than the corresponding width and/or height argument(s).
widthxheight<   Enlarges an image with dimension(s) smaller than the corresponding width and/or height argument(s).
area@   Resize image to have specified area in pixels. Aspect ratio is preserved.
{size}{offset}  Specifying the offset (default is +0+0). Below, {size} refers to any of the forms above.
{size}{+-}x{+-}y    Horizontal and vertical offsets x and y, specified in pixels. Signs are required for both. Offsets are affected by ‑gravity setting. Offsets are not affected by % or other size operators.

100%例如,我认为它是一个有效的表单(它与scale%上面列表中的第一个表单匹配)。但100%蜻蜓不接受,因为蜻蜓使用这个正则表达式来验证几何参数

^\d*x\d*[><%^!]?$|^\d+@$

基本上任何没有的东西都x被蜻蜓认为是无效的。我误解了 ImageMagick 文档,还是 Dragonfly 正则表达式错误?

4

2 回答 2

1

您正确理解 Imagemagick 文档。Dragonfly 显然不支持 'scale%' 几何形式。Dragonfly 可以将其 RESIZE_GEOMETRY 正则表达式更改为:

^\d*x\d*[><%^!]?$|^\d+[@%]$

或者您可以通过提供如下几何规范来解决它:“100x%”

于 2014-03-17T18:02:54.170 回答
0

实际上,我认为我们可以使用这个正则表达式来创建一个几何匹配系统(警告,巨大的正则表达式)。

(?<size>(?<w>(?:\d*(?:\.\d+)?)?%?)?(?:x(?<h>(?:\d*(?:\.\d+)?)?%?))?)(?<aspect>[!><@^])?(?<offset>(?<x>[+-]\d*(?:\.\d+)?)?(?<y>[+-]\d*(?:\.\d+)?)?)

幸运的是,我解释了如何在这个 gist上找到正则表达式。如果有任何错误,请随时告诉。

于 2015-08-31T16:07:13.580 回答