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: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

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
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

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 »

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: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: jpeg rotate lossless or not?

Post by anthony »

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
https://imagemagick.org/Usage/
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: jpeg rotate lossless or not?

Post by NicolasRobidoux »

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: 10
Joined: 2017-05-08T11:12:41-07:00
Authentication code: 1151

Re: jpeg rotate lossless or not?

Post by FrontierDK »

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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: jpeg rotate lossless or not?

Post by snibgo »

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: 10
Joined: 2017-05-08T11:12:41-07:00
Authentication code: 1151

Re: jpeg rotate lossless or not?

Post by FrontierDK »

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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: jpeg rotate lossless or not?

Post by snibgo »

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: 10
Joined: 2017-05-08T11:12:41-07:00
Authentication code: 1151

Re: jpeg rotate lossless or not?

Post by FrontierDK »

Thank you for your help :)

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