Vips::Image.new_from_file Swaps Width/Height in Rails Server, but Not Console

Đang mở
#423 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rails, ruby
Lĩnh vực
backend, computer-vision

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện hành vi với Vips::Image.new_from_file trong một phiên pry của máy chủ Rails và một Rails console, sử dụng ảnh ví dụ hướng đến EXIF và cùng một đường dẫn tempfile. So sánh các lần gọi không có tùy chọn và với fail: true, sau đó theo dõi cách ruby-vips xử lý các tùy chọn mặc định và siêu dữ liệu hình ảnh trong mỗi runtime. Hoàn tất khi kích thước vẫn chính xác mà không có đối số tùy chọn trong cả hai môi trường.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug
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
  1. Place a binding.pry in any Rails controller action.

  2. 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)
  1. Load the image, apply autorot, and overwrite the tempfile:
image = Vips::Image.new_from_file(tempfile.path)
image.autorot.write_to_file(tempfile.path)
  1. 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
  1. 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
  1. 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

Image

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

Image
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

Ngôn ngữ chính
Ruby
Star
904
Fork
64
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của libvips/ruby-vips

Tất cả issue của libvips/ruby-vips

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.