Sha256: b1168cf8865a3885ad005248476186c8e7c3ad1aad8fe49db7c293803212ba12

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module PaperclipCompression
  class Jpeg < Base

    KEY = :jpeg
    JPEGTRAN_DEFAULT_OPTS = '-copy none -optimize -perfect'

    def initialize(file, first_processor, options = {})
      super(file, first_processor)
      @config = PaperclipCompression::Config.create_with_fallbacks(options, KEY, gem_defaults)
    end

    def make
      begin
        @config.process_file? ? process_file : unprocessed_tempfile
      rescue Cocaine::ExitStatusError => e
        raise Paperclip::Error, "JPEGTRAN : There was an error processing #{@basename}" if @config.whiny
      rescue Cocaine::CommandNotFoundError => e
        raise Paperclip::Errors::CommandNotFoundError.new("Could not run 'jpegtran'. Please install jpegtran.")
      end
    end

    private

    def gem_defaults
      {
        command: command_path('jpegtran'),
        options: JPEGTRAN_DEFAULT_OPTS
      }
    end

    def compress
      Paperclip.run(
        @config.command,
        "#{@config.options} :src_path > :dst_path",
        src_path: @src_path, dst_path: @dst_path
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paperclip-compression-1.0.1 lib/paperclip-compression/jpeg.rb
paperclip-compression-1.0.0 lib/paperclip-compression/jpeg.rb