【发布时间】:2019-05-19 03:33:36
【问题描述】:
在 Rails 5.2 上,我试图通过 ActiveStorage 保存头像,但似乎没有图像方向数据保存在活动存储 blob 中。
我正在通过创建操作 my 上的 file_field 保存头像
#user model
has_one_attached :avatar
private
def avatar_validation
if avatar.attached?
if avatar.blob.byte_size > 1000000
avatar.purge
errors.add(:avatar, 'file is too large')
elsif !avatar.blob.content_type.in?(%w[image/png image/jpg
image/jpeg])
avatar.purge
errors.add(:avatar, 'file type needs to be JPEG, JPG, or PNG')
end
end
end
我一直在阅读 minimagick https://github.com/minimagick/minimagick 的一些文档,但还没有弄清楚如何关联
user.avatar.blob
与
image = MiniMagick::Image.open("input.jpg")
我试过了
image = MiniMagick::Image.open("user.avatar.blob")
但运气不好
我需要尝试解决这个问题,因为存储在活动存储中的一些头像被旋转 90 度显示。
https://edgeguides.rubyonrails.org/active_storage_overview.html 谈到图像处理,但我对 gem rails 推荐的东西也没有运气
【问题讨论】:
标签: ruby-on-rails ruby image-processing rails-activestorage minimagick