I have a JPG image with a known size of 3072x2048. Now I want to rotate that image by any degrees (e.g. 45), while keeping its original size. Thus - using ImageMagick on the command line - I first want to rotate, then crop the image, like this:
convert -rotate 45 -gravity center -crop 3072x2048 +repage original.jpg rotated-45.jpg
By using -gravity center
I specify to crop the center part of the image, which is what I want. This operation produces four output images:
- rotated-45-0.jpg
- rotated-45-1.jpg
- rotated-45-2.jpg
- rotated-45-3.jpg
The first image rotated-45-0.jpg
is exactly the final image I want to get. The other three I don't need. I could delete them, but I think it would be nicer to not generate these "extra" images in the first place. So I thought I could do it with this command instead:
convert -rotate 45 -gravity center -crop 3072x2048+0+0 +repage original.jpg rotated-45.jpg
This only produces one output image, however, now the top-left corner of the image is being cropped. So apparently the -gravity center
is not used any longer.
Any ideas what I am missing here?
question from:
https://stackoverflow.com/questions/66048971/rotate-and-crop-an-image-while-keeping-its-original-size 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…