Simple demo of a Carrierwave uploader that uses MiniMagick to darken the uploaded images.
Created
November 16, 2015 17:50
-
-
Save pfac/e7202de2d4ce9a0ee4ad to your computer and use it in GitHub Desktop.
Carrierwave upload with darken filter
This file contains 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 characters
class PhotoUploader < CarrierWave::Uploader::Base | |
include CarrierWave::MiniMagick | |
storage :file | |
def store_dir | |
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | |
end | |
def extension_white_list | |
%w(jpg jpeg gif png) | |
end | |
version :dark do | |
process darken: 0.5 | |
end | |
def darken(ratio) | |
manipulate! do |image| | |
image.fill 'black' | |
image.colorize "#{100 * ratio}%" | |
image = yield image if block_given? | |
image | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment