Bug in Distorting (SRT/ScaleRotateTranslate) documentation

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
conrad.hughes
Posts: 1
Joined: 2017-03-20T14:51:51-07:00
Authentication code: 1151

Bug in Distorting (SRT/ScaleRotateTranslate) documentation

Post by conrad.hughes »

The final example for "Methods of rotating images" in the "Distorting" documentation gives a potentially extremely useful incantation for upscaling an image while rotating, such that the output image is the largest rectangle that would fit into the rotated original (chopping off corners as necessary):

http://www.imagemagick.org/Usage/distor ... te_methods

Unfortunately the formula is incomplete, as it only works when image width is greater than height; trying it out on a portrait image will leave muck in the corners of the image. An example of the complete solution to this problem is described here on Stack Overflow:

http://stackoverflow.com/questions/33866535/

.. and here's an ImageMagick version of same that works in all cases (I hope!):

angle=20
convert rose: -distort SRT \
"%[fx:aa=$angle*pi/180;max((w*abs(cos(aa))+h*abs(sin(aa)))/w,(w*abs(sin(aa))+h*abs(cos(aa)))/h)], $angle" \
rotate_correction.png

The obvious factoring-out of "c=abs(cos(aa));s=abs(sin(aa));" etc. didn't seem to work, but I'm pretty illiterate with ImageMagick - I'm sure someone more expert could improve it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bug in Distorting (SRT/ScaleRotateTranslate) documentation

Post by fmw42 »

Perhaps I misunderstand, but have tried using +distort so that the image size is made larger to accommodate the resulting new size? Or do you just want to rotate the image and keep the input size. Either way, you do not need any computations, just the rotation angle.

If you are saying simply that the described( which one exactly? ) example has the wrong formulae, then it is just a documentation error that would need to go to Anthony, the author of those documents. I can notify him of the issue, once you clarify and point out the exact example.
Post Reply