Class: BT::JpegOptim

Inherits:
BinaryTransformer::Transformer
  • Object
show all
Defined in:
lib/bt_jpegoptim.rb

Instance Method Summary collapse

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_typeArray<String>

Returns:

  • (Array<String>)


29
30
31
# File 'lib/bt_jpegoptim.rb', line 29

def accepted_type
	["image/jpeg"]
end

#argumentsObject



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