Created
May 9, 2013 18:50
-
-
Save jordantomax/5549627 to your computer and use it in GitHub Desktop.
Revisions
-
jordantomax created this gist
May 9, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ task :update_images => :environment do WorkImage.all.each do |model| if model.image.present? model.image.recreate_versions! model.save end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick storage :file # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end # Provide a default URL as a default if there hasn't been a file uploaded: # def default_url # "/images/fallback/" + [version_name, "default.png"].compact.join('_') # end # Process files as they are uploaded: version :display, :if => :not_thumbnail? do process :resize_to_fit => [875, 1500] end version :thumbnail, :if => :thumbnail? do process :resize_to_fit => [150, 200] process :sepiatone end process :store_geometry def thumbnail? file model.thumbnail_enabled? end def not_thumbnail? file !model.thumbnail_enabled? end def store_geometry if @file && model img = ::Magick::Image::read(@file.file).first model.width = img.columns model.height = img.rows end end def sepiatone manipulate! do |img| # Convert the color image to monochrome img = img.quantize(256, Magick::GRAYColorspace).colorize(0.30, 0.30, 0.30, '#cc9933') end end # white list def extension_white_list %w(jpg jpeg gif png) end # Override the filename of the uploaded files: # Avoid using model.id or version_name here, see uploader/store.rb for details. # def filename # "something.jpg" if original_filename # end end