Resize original image in Paperclip

早过忘川 提交于 2019-12-04 22:52:10
Caley Woods

I'm not sure paperclip does resizing by itself. You might have to look at Rmagick to get this done. I would try to get RMagick going (or minimagick) and then use a before_save callback to execute a :resize method that you write that tells RMagic to resize the image. Your method might look like:

class Image < ActiveRecord::Base
  belongs_to :profile
  before_save :resize

  def resize
    self.image = self.image.resize "1024x1024"
  end
end

or

class Image < ActiveRecord::Base
  belongs_to :profile
  before_save do
    self.image = self.image.resize "1024x1024"
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!