lizarisk
lizarisk

Reputation: 7820

How to rotate an image without changing its size?

When an image is rotated by convert -rotate command the image size is enlarged. Is there a way to rotate around the center and to keep the image size, cropping the edges?

Upvotes: 25

Views: 23121

Answers (4)

PolarBear2015
PolarBear2015

Reputation: 844

If you know the size of the image the following works:

convert -rotate 45 -gravity center -crop NxN input output

tested with square images. there may be a way to specify NxN is the input image size.

Upvotes: 4

scrat.squirrel
scrat.squirrel

Reputation: 3826

This seems now to simply "just work" -- for counter-clockwise 90 degrees:

$ convert image.jpg -rotate -90 rotated_ccw.jpg

Upvotes: 4

Enyby
Enyby

Reputation: 4420

convert image.jpg -distort SRT -45 rotate_cropped_image.png

See http://www.imagemagick.org/Usage/warping/#animations

Example: Animated GIF

See also help on -distort: http://www.imagemagick.org/script/command-line-options.php?#distort

Upvotes: 34

lizarisk
lizarisk

Reputation: 7820

I've found this answer on Imagemagick forum:

A simple solution without knowing what the original size of the image was, is to use the Alpha Composite Operator 'Src' as a 'crop to this image size' type of operation. See:

http://www.cit.gu.edu.au/~anthony/graphics/imagick6/compose/#src

For example (ImageMagick version 6 only):

convert image.jpg \( +clone -background black -rotate -45 \) \
    -gravity center -compose Src -composite rotate_cropped_image.png

Upvotes: 0

Related Questions