0

ImageMagick documentation says the following are valid image geometry argument forms:

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.

I take it to mean 100%, for example, is a valid form (it matches the scale% form, the first one in the list above). But 100% isn't accepted by Dragonfly because Dragonfly uses this regex to validate geometry arguments:

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

Basically anything without an x is considered invalid by Dragonfly. Am I misunderstanding the ImageMagick documentation, or is the Dragonfly regex wrong?

Bad Request
  • 3,990
  • 5
  • 33
  • 37

2 Answers2

1

You understand the Imagemagick documentation correctly. Dragonfly apparently doesn't support the 'scale%' geometry form. Dragonfly could change its RESIZE_GEOMETRY regexp to this:

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

or you could work around it by giving a geometry spec like: "100x%"

retroj
  • 717
  • 6
  • 13
0

Actually, I think that we could use this regexp to create a geometry-matching system (warning, huge regexp).

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

Fortunately, I explain how to find the regexp on this gist. If there's any error, feel free to tell.

Alex Rock
  • 831
  • 6
  • 26