Libvips: `auto_rotate` doesn't work as expected. Processed image is wrongly rotated.

Created on 19 May 2019  路  4Comments  路  Source: libvips/libvips

I am trying to process an image taken by specifically S9+. Image looks normal on Windows. I transfer that image to Linux (Debian) and process via ruby. Output is always 90-degree rotated. It should rotate correctly same as input. :autorotate key didn't help.

Sample Image: 20190519_225024.zip

_Sample has vertically usb stick. Output is always horizontally._

Please also see our discussion here: https://github.com/janko/image_processing/issues/52

However, I ran the same script on Windows with libvips 8.6.4, output is correct. I get correct rotation. Same as input.

I also did one last test. Ran the script in Linux then copy output file to windows and I see that they are rotated wrongly.

Linux server has libvips 8.7.4. Also installed 8.8.0-rc3 recently. Both has the same behavior.

Also, @janko confirms that it works on Mac too.

What might be the problem?

_I was woking on Golang previously, when i upload and process such images (like the attached one) i always get the correct result with :autorotate. But not this time on ruby_

Script:

require "vips"

file_path = "./20190518_094223.jpeg"

Vips::Image
  .new_from_file(file_path, autorotate: true)
  .write_to_file("autorotated_1.png")

Vips::Image
  .new_from_file(file_path)
  .autorot
  .write_to_file("autorotated_2.png")

Vips::Image
  .jpegload(file_path, autorotate: true)
  .write_to_file("autorotated_3.png")

Vips::Image
  .thumbnail(file_path, size, height: size)
  .write_to_file("autorotated_4.png")

Vips::Image
  .thumbnail(file_path, size, height: size, auto_rotate: true)
  .write_to_file("autorotated_5.png")

Update:

I open that image with mspaint, draw a line randomly. Saved it. Then processed with above script and output is correct. This is really weird.

question

Most helpful comment

Since I see your answer, i can't stop laughing to myself. How did I missed that!

Yes, libexif-dev is not installed on the machine...

Issue resolved by rebuilding with libexif-dev.

(Seriously, 馃槖 how did i missed that)

Thank you!

All 4 comments

Hello @gencer,

Just a guess, but could your libvips on Debian have been built without libexif?

Without exif support, libvips will unable to see the orientation tag on the image and will not rotate it.

To test, try reading the orientation tag at the command-line, eg.

$ vipsheader -f orientation ~/pics/Portrait_6.jpg 
6

Since I see your answer, i can't stop laughing to myself. How did I missed that!

Yes, libexif-dev is not installed on the machine...

Issue resolved by rebuilding with libexif-dev.

(Seriously, 馃槖 how did i missed that)

Thank you!

Glad it's working now!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

helloqhx picture helloqhx  路  3Comments

harukizaemon picture harukizaemon  路  4Comments

sonylifull picture sonylifull  路  4Comments

solisoft picture solisoft  路  3Comments

kloczek picture kloczek  路  3Comments