class BT::JpegOptim

Public Class Methods

new(strip_all: true, progressive: true, quality: 75) click to toggle source
# File lib/bt_jpegoptim.rb, line 11
def initialize(strip_all: true, progressive: true, quality: 75)
        raise ArgumentError.new "Quality cannot be lower than 0%" if quality < 0
        raise ArgumentError.new "Quality cannot exceed 100%" if quality > 100
        @strip = strip_all ? "-s" : ""
        @quality = "--max=#{quality}"
        @progressive = progressive ? "--all-progressive" : "--all-normal"
end

Public Instance Methods

accepted_type() click to toggle source

@return [Array<String>]

# File lib/bt_jpegoptim.rb, line 29
def accepted_type
        ["image/jpeg"]
end
arguments() click to toggle source
# File lib/bt_jpegoptim.rb, line 23
def arguments
        ["--stdin", "--stdout", @strip, @quality, @progressive]
                .select {|x| !x.empty? && !x.nil?}
end
transform(bytes) click to toggle source
# File lib/bt_jpegoptim.rb, line 19
def transform(bytes)
        "jpegoptim #{arguments.join " " }" << bytes
end