Last active
May 4, 2017 17:33
-
-
Save tedgrubb/db81f606ae4974325769 to your computer and use it in GitHub Desktop.
Paperclip Processor that finds the background color and replaces it with a transparent background. Also simulates anti-aliasing using '-fuzz' to get rid of pixelated artifacts.
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
# lib/paperclip_processors/transparency.rb | |
module Paperclip | |
class Transparency < Thumbnail | |
# Find the background and replace with transparency. | |
# -fuzz 20% simulates antialiasing | |
CONVERT_OPTIONS = [ | |
'-alpha', 'set', | |
'-fill', 'white', | |
'-draw', "'color 0,0 replace'", | |
'-fuzz', '20%', | |
'-transparent', 'white' | |
] | |
# Append the convert options to existing options | |
# defined via style and convert_options | |
def transformation_command | |
super + CONVERT_OPTIONS | |
end | |
end | |
end | |
# Usage | |
# has_attached_file :logo, | |
# styles: { small: ['150x50', :png] }, | |
# processors: [:transparency] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment