Class: BT::JpegOptim
- Inherits:
-
BinaryTransformer::Transformer
- Object
- BinaryTransformer::Transformer
- BT::JpegOptim
- Defined in:
- lib/bt_jpegoptim.rb
Instance Method Summary collapse
- #accepted_type ⇒ Array<String>
- #arguments ⇒ Object
-
#initialize(strip_all: true, progressive: true, quality: 75) ⇒ JpegOptim
constructor
A new instance of JpegOptim.
- #transform(bytes) ⇒ Object
Constructor Details
#initialize(strip_all: true, progressive: true, quality: 75) ⇒ JpegOptim
Returns a new instance of JpegOptim.
11 12 13 14 15 16 17 |
# 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 |
Instance Method Details
#accepted_type ⇒ Array<String>
29 30 31 |
# File 'lib/bt_jpegoptim.rb', line 29 def accepted_type ["image/jpeg"] end |
#arguments ⇒ Object
23 24 25 26 |
# File 'lib/bt_jpegoptim.rb', line 23 def arguments ["--stdin", "--stdout", @strip, @quality, @progressive] .select {|x| !x.empty? && !x.nil?} end |
#transform(bytes) ⇒ Object
19 20 21 |
# File 'lib/bt_jpegoptim.rb', line 19 def transform(bytes) "jpegoptim #{arguments.join " " }" << bytes end |