-
-
Save bradherman/f7308bb11672929acc78e1a0d28dd2dd to your computer and use it in GitHub Desktop.
Blurring images in Rails with Paperclip custom processor
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 characters
module Paperclip | |
class Blur < Processor | |
def initialize file, options = {}, attachment = nil | |
super | |
@format = File.extname(@file.path) | |
@basename = File.basename(@file.path, @format) | |
end | |
def make | |
src = @file | |
dst = Tempfile.new([@basename, @format]) | |
dst.binmode | |
begin | |
parameters = [] | |
parameters << ":source" | |
parameters << "-blur 0x8" | |
parameters << ":dest" | |
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ") | |
success = Paperclip.run("convert", parameters, :source => "#{File.expand_path(src.path)}[0]", :dest => File.expand_path(dst.path)) | |
rescue PaperclipCommandLineError => e | |
raise PaperclipError, "There was an error during the blur conversion for #{@basename}" if @whiny | |
end | |
dst | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment