Class: PaperclipCompression::Png

Inherits:
Base
  • Object
show all
Defined in:
lib/paperclip-compression/png.rb

Constant Summary collapse

OPTIPNG_DEFAULT_OPTS =
'-o 5'

Instance Method Summary collapse

Methods inherited from Base

make

Constructor Details

#initialize(file, options = {}) ⇒ Png

Returns a new instance of Png.



6
7
8
9
10
# File 'lib/paperclip-compression/png.rb', line 6

def initialize(file, options = {})
  super(file, options)
  @src_path = File.expand_path(@file.path)
  @cli_opts = init_cli_opts(:png, default_opts)
end

Instance Method Details

#makeObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/paperclip-compression/png.rb', line 12

def make
  begin
    Paperclip.run(command_path('optipng'), "#{@cli_opts} :src_path", src_path: @src_path) if @cli_opts
    @file
  rescue Cocaine::ExitStatusError => e
    raise Paperclip::Error, "OPTIPNG : There was an error processing the thumbnail for #{@basename}" if @whiny
  rescue Cocaine::CommandNotFoundError => e
    raise Paperclip::Errors::CommandNotFoundError.new("Could not run 'optipng'. Please install optipng.")
  end
end