banhpho 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -1
- data/README.md +7 -13
- data/lib/banhpho/cli.rb +35 -16
- data/lib/banhpho/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 751cc27910314973aaeb03ef4ce9616034170913
|
4
|
+
data.tar.gz: a9a63e818cbba4478faf9098d8484e59b8d9148c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59f1453d94cb2bfb7b53a1fa4e32aeb838296b019cdc255b274f56a33c5f5d111c0bba40ee02e2fc399cb36f10f442ac2c4caa7f8402631287f60c7d783bb19f
|
7
|
+
data.tar.gz: 08f059a1ca67b8a6b82426c208836a5de81d940527894ae9e10860378225d33ffcb5f03569277b1d91b29728cb3a319e4601098e22524772ad963c8ed18edc96
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,26 +1,20 @@
|
|
1
|
-
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/banhpho.svg)](https://badge.fury.io/rb/banhpho)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
## Installation
|
3
|
+
# Banh Pho
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'banhpho'
|
11
|
-
```
|
5
|
+
A wrapper of [pngquant](https://pngquant.org/) for compressing all PNG files in a directory.
|
12
6
|
|
13
|
-
|
7
|
+
## Dependency
|
14
8
|
|
15
|
-
|
9
|
+
Make sure you already download [pngquant](https://pngquant.org/releases.html) and put its location in `PATH` so `banhpho` can locate the executable.
|
16
10
|
|
17
|
-
|
11
|
+
## Installation
|
18
12
|
|
19
13
|
$ gem install banhpho
|
20
14
|
|
21
15
|
## Usage
|
22
16
|
|
23
|
-
|
17
|
+
$ banhpho compress [DIR]
|
24
18
|
|
25
19
|
## Development
|
26
20
|
|
data/lib/banhpho/cli.rb
CHANGED
@@ -1,22 +1,41 @@
|
|
1
1
|
require "thor"
|
2
|
+
require 'colorize'
|
3
|
+
require 'progress_bar'
|
4
|
+
require 'terminal-table'
|
2
5
|
|
3
6
|
module Banhpho
|
4
7
|
class CLI < Thor
|
5
8
|
|
6
9
|
desc "compress DIR", "compress all png files in DIR"
|
7
10
|
def compress(dir)
|
8
|
-
@count = 0
|
9
|
-
@originalSize = 0
|
10
|
-
@newSize = 0
|
11
|
-
|
12
11
|
abort("Error: command pngquant is not found, please download it from https://pngquant.org/ and put it in your global path") unless command?("pngquant")
|
13
12
|
abort("Error: argument '#{dir}' is not a valid directory") unless File.directory?(dir)
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
originalSize = 0
|
15
|
+
newSize = 0
|
16
|
+
|
17
|
+
imgs = []
|
18
|
+
compressInDir(dir) do |f|
|
19
|
+
imgs << f
|
20
|
+
originalSize += File.size(f)
|
21
|
+
end
|
22
|
+
bar = ProgressBar.new(imgs.size)
|
23
|
+
imgs.each do |f|
|
24
|
+
%x(pngquant --force --ext .png --skip-if-larger -- #{f})
|
25
|
+
bar.increment!
|
26
|
+
newSize += File.size(f)
|
27
|
+
end
|
28
|
+
|
29
|
+
count = imgs.size
|
30
|
+
|
31
|
+
if count > 0
|
32
|
+
rows = []
|
33
|
+
rows << ['Number of files', count]
|
34
|
+
rows << ['Original size', prettyFileSize(originalSize)]
|
35
|
+
rows << ['New size', prettyFileSize(newSize)]
|
36
|
+
rows << ['Compression ratio', "#{(1 - newSize.to_f / originalSize).round(4) * 100}%"]
|
37
|
+
report = Terminal::Table.new :title => 'Task completed', :rows => rows
|
38
|
+
puts report
|
20
39
|
end
|
21
40
|
end
|
22
41
|
|
@@ -26,24 +45,24 @@ module Banhpho
|
|
26
45
|
puts VERSION
|
27
46
|
end
|
28
47
|
|
48
|
+
desc "author", "print the author info"
|
49
|
+
def author()
|
50
|
+
puts 'Created by heartace [love@heartace.me], with ' + '♥'.colorize(:magenta)
|
51
|
+
end
|
52
|
+
|
29
53
|
no_commands do
|
30
54
|
def compressInDir (dir)
|
31
55
|
Dir.foreach(dir) do |item|
|
32
56
|
next if item == "." or item == ".."
|
33
57
|
path = File.join(dir, item)
|
34
58
|
if File.directory?(path)
|
35
|
-
puts("checking directory: #{path}")
|
36
59
|
compressInDir(path)
|
37
60
|
next
|
38
61
|
end
|
39
62
|
ext = File.extname(path).downcase
|
40
63
|
if ext == ".png" then
|
41
|
-
|
42
|
-
|
43
|
-
puts(" compressing file: #{path}")
|
44
|
-
%x(pngquant --force --ext .png --skip-if-larger -- #{exePath})
|
45
|
-
@count += 1
|
46
|
-
@newSize += File.size(path)
|
64
|
+
fixedPath = path.gsub(/ /, "\\ ")
|
65
|
+
yield fixedPath
|
47
66
|
end
|
48
67
|
end
|
49
68
|
end
|
data/lib/banhpho/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banhpho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- heartace
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|