Module: Optipng
- Defined in:
- lib/optipng.rb
Overview
The optipng
tool command frontend.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- COMMAND =
Holds
optipng
command. :optipng
- MATCHERS =
Holds output matchers.
[ /^Processing\:\s*(.*)/, /^Error:\s*(.*)/, /(\d+\.\d+)%/, /already optimized\.$/, ]
Class Method Summary collapse
-
.available? ⇒ Boolean
Checks if
jpegoptim
is available. -
.optimize(paths, options = { }) ⇒ Struct
Performs optimizations above file or set of files.
Class Method Details
.available? ⇒ Boolean
Checks if jpegoptim
is available.
43 44 45 |
# File 'lib/optipng.rb', line 43 def self.available? return Whereis.available? self::COMMAND end |
.optimize(paths, options = { }) ⇒ Struct
Performs optimizations above file or set of files.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/optipng.rb', line 57 def self.optimize(paths, = { }) # Command cmd = CommandBuilder::new(self::COMMAND) # Max if [:level].kind_of? Integer cmd.arg(:o, [:level].to_i) end # Files if paths.kind_of? String paths = [paths] end # Runs the command cmd << paths if [:debug] == true STDERR.write cmd.to_s + "\n" end output = Pipe.run(cmd.to_s) # Parses output succeed, errors = __parse_output(output) return self::Result::new(succeed, errors) end |