-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Bug Description
When loading an image from a file path, Vips::Image.new_from_file(path) returns swapped width and height dimensions. This issue only occurs when the code is executed within a Rails server process (e.g., Puma/Unicorn). The exact same code, reading the exact same file path, returns the correct dimensions when run from a rails console.
A peculiar workaround is that providing any optional argument to the method call (e.g., fail: true or autorotate: false) corrects the behavior in the server environment. This suggests a potential issue with how default options are handled or a caching-related problem specific to the server runtime.
Steps to Reproduce
-
Place a binding.pry in any Rails controller action.
-
In the pry session, download an image that has EXIF orientation data:
require 'down'
url = 'https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_6.jpg'
tempfile = Down.download(url)
- Load the image, apply autorot, and overwrite the tempfile:
image = Vips::Image.new_from_file(tempfile.path)
image.autorot.write_to_file(tempfile.path)
- Reload the image from the same path without any options and inspect its dimensions. The dimensions will be swapped.
# In the server pry session
reloaded_image = Vips::Image.new_from_file(tempfile.path)
puts "BUG -> In Server: #{reloaded_image.width}x#{reloaded_image.height}"
# Example Output: BUG -> In Server: 3024x4032
path = tempfile.path # Copy this path for the next step
- In a new terminal, open a rails console. Use the path from the previous step to load the same file:
# In the rails console session
console_image = Vips::Image.new_from_file('PASTE_THE_TEMPFILE_PATH_HERE')
puts "OK -> In Console: #{console_image.width}x#{console_image.height}"
# Example Output: OK -> In Console: 4032x3024
- Go back to the server pry session. Run the same command but add any option, like fail: true. The dimensions will now be correct.
# Back in the server pry session
workaround_image = Vips::Image.new_from_file(tempfile.path, fail: true)
puts "FIXED -> Server with option: #{workaround_image.width}x#{workaround_image.height}"
# Example Output: FIXED -> Server with option: 4032x3024
Expected Behavior
Vips::Image.new_from_file(tempfile.path) should consistently return the correct dimensions (4032x3024 for the example image) in all execution environments, including the Rails server.
Actual Behavior
The dimensions are swapped (3024x4032) only when run inside a Rails server without any extra options. The dimensions are correct when run in a Rails console or when any option is added to the method call in the server.
Screenshots
This is the correct behaviour after adding an option

Top terminal is the Rails server; bottom terminal is the Rails console:

Desktop
- OS:Fedora 42(local) and ubuntu (production environment)
- Ruby-vips 2.2.3
- libvips 8.16.1 (on all envs)
Thank you in advance