Page 1 of 1

How to rotate a *.jpg picture by 90 deg?

Posted: 2012-07-02T00:39:41-07:00
by bensto
Assume I have a *.jpg picture

D:\mypicture\holidayjune\pic123.jpg

How can I lossless rotate this picture by 90 clockwise and save it as

D:\mypicture\holidayjune\pic123rot.jpg

?

What do I have to change in the previous command when I want to rotate it couter clockwise by 90 deg?

Ben

Re: How to rotate a *.jpg picture by 90 deg?

Posted: 2012-07-02T02:38:34-07:00
by Bonzo
I do not think you can do a lossless rotate with IM.

clockwise -rotate 90
anticlockwise -rotate 270 ( -90 may work )

Re: How to rotate a *.jpg picture by 90 deg?

Posted: 2012-07-02T10:23:41-07:00
by fmw42
Even if the rotate 90 were lossless, just reading in a jpg and writing it out again would have some losses. JPG is a lossy compression image format. IM must read the input, decompress, recompress and write the ouput even to just copy the image. Other non-im solutions may be available. see

http://www.imagemagick.org/Usage/formats/#jpg_non-im
http://www.imagemagick.org/Usage/formats/#jpg_lossless

Re: How to rotate a *.jpg picture by 90 deg?

Posted: 2012-07-02T11:08:05-07:00
by Dane Vandeputte
fmw42 wrote:Even if the rotate 90 were lossless, just reading in a jpg and writing it out again would have some losses. JPG is a lossy compression image format.
Actually, as it turns out, one can losslessly rotate by multiples of 90 degrees (or transpose) a JPEG file by doing nothing more than rearranging and/or changing signs of the quantized DCT coefficients in each block.

In reply to Ben, you can use the freely available jpegtran.

Use the following command to rotate input.jpg 90 degrees clockwise and save the result to output.jpg:

jpegtran -rotate 90 input.jpg output.jpg

If the input image dimensions are not multiples of the JPEG block size, you may notice a small, undesirable border along some portions of the image. To eliminate the border, use the following command instead:

jpegtran -rotate 90 -trim input.jpg output.jpg

In either case, if you want to rotate 90 degrees counter-clockwise, replace the 90 in either command with 270. Also, here is the jpegtran manual for further reference.

Re: How to rotate a *.jpg picture by 90 deg?

Posted: 2012-07-02T18:26:55-07:00
by anthony
See...IM examples, Photo Handling for just a quick answer.
http://www.imagemagick.org/Usage/photos/#orient

For a complete answer, see...
Common Image file Formats, Lossless JPEG Processing (non-IM)
http://www.imagemagick.org/Usage/formats/#jpg_lossless