Module: TinyPng::Shrink
- Included in:
- Client
- Defined in:
- lib/tiny_png/shrink.rb
Instance Method Summary collapse
-
#shrink(*paths) ⇒ Object
Replace an image at a given path with its shrunken version.
Instance Method Details
#shrink(*paths) ⇒ Object
Replace an image at a given path with its shrunken version
The image at the given path will be submitted to TinyPNG and the new version will overwrite the original. If this process fails for any reason, the original file will be rolled back.
Arguments:
-
shrinkwrap (any number of objects to be shrunk) You can pass in a directory, or individual files that should be shrunk. All should be absolute paths.
If you send in a path to a specific file, it must end in ‘.png` or it will not be sent to TinyPNG for processing.
Likewise, when traversing through a directory, only files that end in ‘.png` will be examined.
All paths to specific files (whether sent in directly or picked out from the directory) need to be readable and writeable.
Returns: Hash { :success => [Array, Of, Paths, Successfully, Overwrittern], :failure => [Array, Of, Paths, Left, Unchanged] }
21 22 23 24 25 26 27 28 |
# File 'lib/tiny_png/shrink.rb', line 21 def shrink *paths results = { :success => [], :failure => [] } TinyPng::Path.get_all(paths).each do |path| key = shrink_in_place(path) ? :success : :failure results[key].push path end results end |