Frage

I upload images to the server with paperclip. I scale medium images with the following code:

:medium => "280x100>"

But Also I need to fit the original image filesize to 1Mb. Is there any way to do this with the paperclip functionality?

War es hilfreich?

Lösung

There is no such ability at the moment, but you can add validation for file size as described there https://github.com/thoughtbot/paperclip#validations , so it will look like this:

validates_attachment :avatar, :size => { :less_than => 1.megabytes }

Andere Tipps

I don't know how change image size in file size but you can resize original image:

class Image < ActiveRecord::Base
  before_save :resize

  def resize
    self.image = self.image.resize "1024x1024"
  end
end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top