Class: Paperclip::Thumbnail
- Inherits:
-
Processor
- Object
- Processor
- Paperclip::Thumbnail
- Defined in:
- lib/paperclip-smusher.rb
Instance Method Summary collapse
-
#make ⇒ Object
Performs the conversion of the
file
into a thumbnail.
Instance Method Details
#make ⇒ Object
Performs the conversion of the file
into a thumbnail. Returns the Tempfile that contains the new image.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/paperclip-smusher.rb', line 6 def make src = @file conv = Tempfile.new([@basename, @format ? ".#{@format}" : '']) conv.binmode dst = Tempfile.new([@basename, @format ? ".#{@format}" : '']) dst.binmode begin parameters = [] parameters << parameters << ":source" parameters << transformation_command parameters << parameters << ":dest" parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ") success = Paperclip.run("convert", parameters, :source => "#{File.(src.path)}#{'[0]' unless animated?}", :dest => File.(conv.path)) if conv.size > 0 format = begin Paperclip.run("identify", "-format %m :file", :file => "#{File.(conv.path)}[0]") rescue PaperclipCommandLineError "" end case format.strip when 'JPEG' # Part of libjpeg-progs deb package success = Paperclip.run('jpegtran', "-copy none -optimize -perfect :source > :dest", :source => File.(conv.path), :dest => File.(dst.path)) when 'PNG' success = Paperclip.run('pngcrush', "-rem alla -reduce -brute :source :dest", :source => File.(conv.path), :dest => File.(dst.path)) else dst = conv end end rescue Cocaine::ExitStatusError => e raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if @whiny rescue Cocaine::CommandNotFoundError => e raise Paperclip::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.") rescue Exception => e Rails.logger.error "There was an error processing the thumbnail for #{@basename}. Check imagemagick, jpegtran and pngcrush installed." Rails.logger.error e. end dst.size > 0 ? dst : conv end |