Sha256: 3b0bab1151fb2dc4c3d459d1a87aa2d25c01d9426c2b309a15afcb23dcb85460

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 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 ExitStatusError
        raise Paperclip::Error, "JPEGTRAN : There was an error processing #{@basename}" if @config.whiny
      rescue CommandNotFoundError
        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

7 entries across 7 versions & 2 rubygems

Version Path
kt-paperclip-compression-1.2.2 lib/paperclip-compression/jpeg.rb
kt-paperclip-compression-1.2.1 lib/paperclip-compression/jpeg.rb
paperclip-compression-2.0.0 lib/paperclip-compression/jpeg.rb
kt-paperclip-compression-1.2.0 lib/paperclip-compression/jpeg.rb
paperclip-compression-1.1.1 lib/paperclip-compression/jpeg.rb
paperclip-compression-1.1.0 lib/paperclip-compression/jpeg.rb
paperclip-compression-1.0.2 lib/paperclip-compression/jpeg.rb