Bug in Distorting (SRT/ScaleRotateTranslate) documentation
Posted: 2017-03-20T15:11:20-07:00
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.
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.