Skip to content

Instantly share code, notes, and snippets.

@somebox
Created November 25, 2009 13:44
Show Gist options
  • Save somebox/242707 to your computer and use it in GitHub Desktop.
Save somebox/242707 to your computer and use it in GitHub Desktop.
Downsample attachment_fu images
class Image << ActiveRecord::Base
has_attachment :storage => :file_system,
:content_type => :image,
:processor => 'rmagick',
# ...
named_scope :large, :conditions => "size > #{1.megabytes}"
DEFAULT_QUALITY = 60
# ...
def downsample!(quality=DEFAULT_QUALITY)
image = Magick::ImageList.new(self.absolute_filename)
image.write("jpeg:#{self.absolute_filename}") {self.quality = quality}
end
def absolute_filename
File.join(Rails.root, 'public', self.public_filename)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment