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

未关闭
#423 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
rails, ruby

调研方向

首先,在 Rails 服务器的 pry 会话和 Rails 控制台中使用 Vips::Image.new_from_file 重现该行为,使用面向 EXIF 的示例图像和相同的 tempfile 路径。比较不带选项的调用和带 fail: true 的调用,然后跟踪 ruby-vips 在每个运行时中如何处理默认选项和图像元数据。当两个环境中不带可选参数时尺寸仍然正确,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Ruby
星标
904
派生
64
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

libvips/ruby-vips 的其他 Issue

查看 libvips/ruby-vips 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。