Class: Mpngquant::Pngquant
- Inherits:
-
Object
- Object
- Mpngquant::Pngquant
- Defined in:
- lib/mpngquant.rb
Class Method Summary collapse
- .optimize(infile:, force: nil, skip_if_larger: nil, ext: nil, quality: nil, speed: nil, nofs: nil, posterize: nil, strip: nil, verbose: nil) ⇒ Object
-
.supported? ⇒ True
Whether pngquant exists or not?.
Class Method Details
.optimize(infile:, force: nil, skip_if_larger: nil, ext: nil, quality: nil, speed: nil, nofs: nil, posterize: nil, strip: nil, verbose: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mpngquant.rb', line 21 def optimize(infile:, force: nil, skip_if_larger: nil, ext: nil, quality: nil, speed: nil, nofs: nil, posterize: nil, strip: nil, verbose: nil) pngquant = "pngquant" unless quality.nil? parsed_quality = ["--quality", quality] end unless speed.nil? parsed_speed = ["--speed", Integer(speed).to_s] end parsed_infile = Pathname(infile).cleanpath.to_s unless infile.nil? File.open(parsed_infile) do |f| read_infile = f.read arg = [pngquant, parsed_quality, parsed_speed, "-"].select { |v| !v.nil? }.flatten! Open3.capture2(*arg, :stdin_data => read_infile) end end |
.supported? ⇒ True
Whether pngquant exists or not?
13 14 15 16 17 18 19 |
# File 'lib/mpngquant.rb', line 13 def supported? args = ["pngquant", "--version"] _, s = Open3.capture2(*args) s rescue Errno::ENOENT false end |