Guest User

Untitled

a guest
May 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. # lib/paperclip_grayscale_processor.rb
  2.  
  3. module Paperclip
  4. class Grayscale < Processor
  5. def initialize file, options = {}, attachment = nil
  6. super
  7. @file = file
  8. @current_format = File.extname(@file.path)
  9. @basename = File.basename(@file.path, @current_format)
  10. end
  11.  
  12. def make
  13. dst = Tempfile.new(@basename)
  14. dst.binmode
  15.  
  16. command = "#{File.expand_path(@file.path)} -colorspace Gray #{File.expand_path(dst.path)}"
  17.  
  18. begin
  19. success = Paperclip.run("convert", command)
  20. rescue PaperclipCommandLineError
  21. raise PaperclipError, "There was an error converting the image to grayscale for #{@basename}"
  22. end
  23.  
  24. dst
  25. end
  26. end
  27. end
Add Comment
Please, Sign In to add comment