Skip to content

Instantly share code, notes, and snippets.

@bradherman
Forked from christianroman/blur.rb
Created August 10, 2016 05:04
Show Gist options
  • Save bradherman/f7308bb11672929acc78e1a0d28dd2dd to your computer and use it in GitHub Desktop.
Save bradherman/f7308bb11672929acc78e1a0d28dd2dd to your computer and use it in GitHub Desktop.
Blurring images in Rails with Paperclip custom processor
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