Page 1 of 1

Bug in Distorting (SRT/ScaleRotateTranslate) documentation

Posted: 2017-03-20T15:11:20-07:00
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.

Re: Bug in Distorting (SRT/ScaleRotateTranslate) documentation

Posted: 2017-03-20T15:23:10-07:00
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.