jpeg rotate lossless or not?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
anthony
Posts: 8867
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony » 2006-02-19T16:39:15-07:00

You can not rotate a jpeg losslessly using IM, or any image program that actually reads and writes the image data.

However the libjpeg library installation has a jpegtran program that adjusts the jpeg data to rotate it without actaullay reading and writing the image. IE it can do it losslessly.

The same problem goes for JPEG comments and other EXIF meta data,
However other programs like jhead can also modify such information without actually touching the image data.

For more pointers see JPEG Image Handling, non-IM solutions http://www.cit.gu.edu.au/~anthony/graph ... jpg_non_im
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

User avatar
magick
Site Admin
Posts: 10690
Joined: 2003-05-31T11:32:55-07:00

Post by magick » 2006-05-04T14:44:26-07:00

90 degree rotation is lossless within ImageMagick but it is not lossless when the pixels are written back out to a JPEG image file. For lossless JPEG rotation, a program needs to manipulate the data directly in the JPEG image file.

baibaichen
Posts: 11
Joined: 2010-03-23T20:32:14-07:00
Authentication code: 8675308

Re: jpeg rotate lossless or not?

Post by baibaichen » 2011-07-14T20:07:01-07:00

For lossless JPEG rotation, a program needs to manipulate the data directly in the JPEG image file.
Is this still true? so I need directly call api of libjpeg other than IM?

User avatar
anthony
Posts: 8867
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: jpeg rotate lossless or not?

Post by anthony » 2011-07-14T21:10:31-07:00

Yes it is still true. As a general image processor, IM does not process images in different ways for different image file formats. You must use special tools for this special need. The same goes for lossless JPEG crop (limited to cell boundaries), or even lossless JPEG insertions (overlay), which is also possible! Though not what I would consider practical for general use.

Also note that lossless JPEG rotations have some limitations. Specifically it will roate the image but if partical blocks are present along the bottom or right edges, these will not be rotated! See the discssion at
http://www.imagemagick.org/Usage/forum_ ... 84&p=62157

Some information about this is given in...
IM Examples, Common File Formats, Lossless JPEG Processing
http://www.imagemagick.org/Usage/formats/#jpg_lossless
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

NicolasRobidoux
Posts: 1943
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Copenhagen, Denmark

Re: jpeg rotate lossless or not?

Post by NicolasRobidoux » 2011-07-18T11:49:28-07:00

For lossless rotation outside of IM, see item 2 of http://sylvana.net/jpegcrop/jpegtran/. This is a high quality library, which runs really fast to boot. (Of course, Anthony's link above mentions it.)

FrontierDK
Posts: 11
Joined: 2017-05-08T11:12:41-07:00
Authentication code: 1151

Re: jpeg rotate lossless or not?

Post by FrontierDK » 2017-08-22T02:27:50-07:00

How about rotation inside ImageMagic? I'm using the DLL version, and I'm noticing that if I load a .JPG file, with the meta-rotation set...Imagemagic doesn't rotate it right if I convert to another format, like BMP...

How does one make ImageMagic use the metainformation upon opening?

snibgo
Posts: 9379
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: jpeg rotate lossless or not?

Post by snibgo » 2017-08-22T02:57:38-07:00

I don't understand your question. Please state your version of IM, the command you used, with the input file(s).

IM rotation, in multiples of 90 degrees, is lossless. Writing to JPEG, which is a lossy format, causes loss.
snibgo's IM pages: im.snibgo.com

FrontierDK
Posts: 11
Joined: 2017-05-08T11:12:41-07:00
Authentication code: 1151

Re: jpeg rotate lossless or not?

Post by FrontierDK » 2017-08-22T04:25:24-07:00

I'm using the latest DLL version, downloaded today.

From VBscript
result=myobject.convert("test.jpg", "test.bmp")

If I load an image, which is stored "upside down" - but has the "rotate 180 degrees" exif set, it's not used.

snibgo
Posts: 9379
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: jpeg rotate lossless or not?

Post by snibgo » 2017-08-22T05:02:07-07:00

IM won't correct the orientation unless you tell it to. See http://www.imagemagick.org/script/comma ... uto-orient . I don't know how to do that in VB.
snibgo's IM pages: im.snibgo.com

FrontierDK
Posts: 11
Joined: 2017-05-08T11:12:41-07:00
Authentication code: 1151

Re: jpeg rotate lossless or not?

Post by FrontierDK » 2017-08-22T05:44:46-07:00

Thank you for your help :)

It's as simple as this:
result=myobject.convert("test.jpg", "-auto-orient", "test.bmp")

Post Reply