【问题标题】:Process `auto_orient` with Cloudinary upload使用 Cloudinary 上传处理 `auto_orient`
【发布时间】:2016-07-10 11:41:15
【问题描述】:

我有一个常规的文件上传,现在我改为使用 Cloudinary。

在上传时,我做了以下操作,以防止从移动设备上传图像时出现方向故障(有关详细信息,请参阅 exif image rotation issue using carrierwave and rmagick to upload to s3):

process :rotate
process :store_dimensions

def rotate
  manipulate! do |image|
    image.tap(&:auto_orient)
  end
end

def store_dimensions
  # This does not work with cloudinary #18

  if file && model
    model.width, model.height = ::MiniMagick::Image.open(file.file)[:dimensions]
  end
end

旋转和存储尺寸都不起作用,因为我切换到 cloudinary。

现在 Cloudinary 有 an official tutuorial 来展示如何做到这一点,但它根本不起作用,其他人似乎也有同样的问题,而且提供的选项都不适合我:

【问题讨论】:

    标签: ruby-on-rails imagemagick carrierwave cloudinary minimagick


    【解决方案1】:

    我能够使用第一个选项的变体使其工作:

      after_save :update_dimensions
    
      def update_dimensions
        if self.image != nil && self.image.metadata.present?
          width = self.image.metadata["width"]
          height = self.image.metadata["height"]
    
          self.update_column(:width, width)
          self.update_column(:height, height)
    
        end
      end
    

    重要提示:由于我们在 after_save 回调中,因此使用 update_column 至关重要,这样我们就不会触发另一个回调并最终陷入无限循环。

    修复提供的解决方案

    self.image.present? 返回falseself.image != nil 返回true

    【讨论】:

      猜你喜欢
      • 2019-05-24
      • 2019-06-18
      • 2014-03-03
      • 2020-04-07
      • 2017-08-30
      • 2015-05-22
      • 2013-08-04
      • 2020-07-25
      • 2015-08-20
      相关资源
      最近更新 更多