JPG to TIFF + 180 rotation results in flip
Swiss army knife of image processing
Brought to you by:
bfriesen
I expected "gm convert -rotate 180 filename.jpg filename.tiff" to create a TIFF with a rotated image. Instead, the image is flipped.
This differs from:
- the imagemagick version, which creates a properly rotated TIFF
- from doing two "rotate 90", creates properly rotated TIFF
- doing "gm convert -rotate 180 filename.jpg filename.tiff", creates a properly rotated JPG
Example:
Good: convert -rotate 180 AFC.JPG im_180_AFC.jpg
Good: gm convert -rotate 180 AFC.JPG gm_180_AFC.jpg
Good: convert -rotate 180 AFC.JPG im_180_AFC.tiff
Bad: gm convert -rotate 180 AFC.JPG gm_180_AFC.tiff
Sourcefile: https://github.com/TimJDFletcher/IMG_7082
Example
Please tell us more. What version of ImageMagick and GraphicsMagick are you using? What program are you using to view the images? I am not seeing a problem here.
This is what I see here with ImageMagick 6.8.9-9 and latest GraphicsMagick code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
scooby:~% tiffinfo im_180_AFC.tiff
TIFF Directory at offset 0x16dc408 (23970824)
Image Width: 3264 Image Length: 2448
Resolution: 72, 72 pixels/inch
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: RGB color
FillOrder: msb-to-lsb
Orientation: row 0 rhs, col 0 top
Samples/Pixel: 3
Rows/Strip: 1
Planar Configuration: single image plane
Page Number: 0-1
White Point: 0.3127-0.329
PrimaryChromaticities: 0.640000,0.330000,0.300000,0.600000,0.150000,0.060000
scooby:~% tiffinfo gm_180_AFC.tiff
TIFF Directory at offset 0x124cb0 (1199280)
Image Width: 3264 Image Length: 2448
Bits/Sample: 8
Sample Format: unsigned integer
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 rhs, col 0 top
Samples/Pixel: 3
Rows/Strip: 16
Planar Configuration: single image plane
Page Number: 0-1
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
DocumentName: gm_180_AFC.tiff
Software: GraphicsMagick 1.4 snapshot-20170126 Q16 http://www.GraphicsMagick.org/
JPEG Tables: (574 bytes)
~~~~~~~~~~~~~~~~~~~~~~~~~~~
I would guess that your viewing program is making some orientation adjustments on its own based on some metadata from the file (some formats may replicate certain metadata several times, including replication in semi-proprietary chunks/profiles). As can be seen from my results (tiffinfo output), the TIFF orientation is claimed to be the same and I am seeing expected results in terms of the actual image data.
GraphicsMagick development code now includes fixes to update orientation in EXIF profiles. GraphicsMagick does not write an EXIF profile in TIFF files.
You are correct, this differs per viewing program. My example was Apple Preview, if I open in Affinity Photo both documents are (incorrectly) flipped along the horizontal axis. Sketch does the same as Preview.
Autodesk Sketchbook opens the gm-version the same (with bad colors) and the im-version is horizontal and is flipped along the (original) vertical axis.
It's a mess... :D
This problem is due to disagreements between viewer programs as to what metadata to use. When in doubt, discard the extra metadata with
-strip *but then the extra metadata would be lost for any other purpose.