Class: PaperclipCompression::Jpeg

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

Constant Summary collapse

JPEGTRAN_DEFAULT_OPTS =
'-copy none -optimize -perfect'

Instance Method Summary collapse

Methods inherited from Base

make

Constructor Details

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

Returns a new instance of Jpeg.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/paperclip-compression/jpeg.rb', line 6

def initialize(file, options = {})
  super(file, options)

  @dst = Tempfile.new(@basename)
  @dst.binmode

  @src_path = File.expand_path(@file.path)
  @dst_path = File.expand_path(@dst.path)

  @cli_opts = init_cli_opts(:jpeg, default_opts)
end

Instance Method Details

#makeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/paperclip-compression/jpeg.rb', line 18

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