Page 1 of 1

Resize, rotate, shear and rotate an image based on Adobe InDesign coordinates

Posted: 2019-05-07T02:58:11-07:00
by matho
Hi,

I need to resize, crop and rotate/shear images based on Adobe InDesign metadata. This works to resize and crop. But I have problems with rotate and shear.

ImageMagick Version is:
- ImageMagick 7.0.8-14 Q16 x86_64
- MacOS 10.12

This is the original image:
https://www.dropbox.com/s/9mn52rjwy6trt ... t.jpg?dl=0

You can see the image placed in InDesign here:
https://www.dropbox.com/s/5co61xcfci7ym ... e.png?dl=0

For the version without rotate and shear, the following command works:

Code: Select all

convert test.jpg -resize 22x22% -crop 1018x687+59+20 test_out.jpg
The result of this is correct.

But for the version with a rotation I get a wrong result. I tried:

Code: Select all

convert input.jpg -resize 22x22% -alpha set \( +clone -background none -rotate -3 \) -gravity center -compose Src -composite -crop 1018x687+59+20 output_rotate1.jpg
and get the following result:
https://www.dropbox.com/s/kj9nnh39caemw ... 1.jpg?dl=0

with -distort SRT I got closer, but not 100% correct:

Code: Select all

convert input.jpg -resize 22x22% -distort ScaleRotateTranslate -3 -crop 1018x687+59+20 ouput_rotate_srt.jpg
result:
https://www.dropbox.com/s/56j1eghx9cejl ... t.jpg?dl=0

The problem is that the X and Y positions are not completely correct. InDesign returns the same X and Y position for images with and without rotation because the upper left corner remains at the same point.
I did not found a way, to calculate the correct X-/Y-Position for ImageMagick based on this values.


The same problem, for the version with rotation and shear:

Code: Select all

convert input.jpg -resize 22x22% -alpha set \( +clone -background none -rotate -3 \) -gravity center -compose Src -composite -alpha set \( +clone -background none -shear 10x0 \) -gravity center -compose Src -composite -crop 1018x687+59+20 output_rotate_and_shear.jpg
result:
https://www.dropbox.com/s/k32z1w27nmg4j ... r.jpg?dl=0

This is an overview of the results I get:
https://www.dropbox.com/s/xgzbfroo1qqio ... t.png?dl=0

Thanks in advanced.
Martin

Re: Resize, rotate, shear and rotate an image based on Adobe InDesign coordinates

Posted: 2019-05-07T05:49:46-07:00
by snibgo
I don't use InDesign, and can't advise on how to translate its parameters to IM.

I suggest you start simple: rotation only, with no resize or crop or shear or anything else. Then try shear in one direction only. Then shear in the other direction only. Gradually build up to the full crop, resize, rotate and shear. The order of these operations matters. In IM, you have full flexibility to apply them in any order you want.

Your IM commands are over-complex. For example, you clone an image, operate on the clone, then "-gravity center -compose Src -composite". Why not simply operate on the input image?

Re: Resize, rotate, shear and rotate an image based on Adobe InDesign coordinates

Posted: 2019-05-07T08:15:36-07:00
by matho
Thanks for your feedback.

I already tried it with the single steps. The resize and crop works.

Rotate an image with ImageMagick enlarges the image. For this reason I made to clone, -gravity center and -compose Src -composite. Then I have the size of the original image.

The problem is that when I use the X and Y position with the crop, the position is not exactly right after rotation.

When I do the following convert, I get about the correct result:

Code: Select all

convert input.jpg -resize 22x22% -distort ScaleRotateTranslate -3 -crop 1018x687+40+53 ouput_rotate_srt.jpg
instead of this convert (with X-/Y-values from InDesign):

Code: Select all

convert input.jpg -resize 22x22% -distort ScaleRotateTranslate -3 -crop 1018x687+59+20 ouput_rotate_srt.jpg
So I'm looking for a formula to get the correct X and Y position values.