image_optimizer 1.6.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b3565bc486b1461c702bb3ee612b49e37f7b93c
4
- data.tar.gz: 9bbfdb3742662c8fec9f0b70a79cf677fcf60d2a
3
+ metadata.gz: ad635514a39378a2f01e3dd15515cf9433b341bd
4
+ data.tar.gz: 3612dc1b7da6cd2e19603f5c82c8a8e259ccd0a9
5
5
  SHA512:
6
- metadata.gz: 3cd3ee2a99e823b2df4e4108724d8e28456f95e2f0b5d290b50b95a7a009631ba7a460aef666ae4d3a18abc3984063ab201e0246223fe921deb8fc375892c380
7
- data.tar.gz: c8389fa53dd8c10169957c83bbaa83ff12c3823bb6d722b6871a11fdd5efb7626d4cbf7997836605b309a25da50784d13cbe0493486a12b37c3a1ffcdefbe3a2
6
+ metadata.gz: 59de349a631136309aa0d97942c49ffb76ca39c249187e91850dd949471c23a16bd85b3e4fef1c0c6ada72f442f01d86c58ce6b75efc68449f83a8dcb5cc4027
7
+ data.tar.gz: 16d02acc88a30773dbed18dc3f7594faa26004dbc8bcfb9491237fd9b737cc8b73efd427f26b482e4518e8c56e710a676384a7fbf30c9cf4a8315416e6db07b6
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -24,10 +24,12 @@ Tested against ruby 2.0.x, 2.1.x, 2.2.x, 2.3.x, and ruby-head
24
24
 
25
25
  3. Gifsicle, which can be installed from [www.lcdf.org/gifsicle/](https://www.lcdf.org/gifsicle/)
26
26
 
27
+ 4. Pngquant, which can be installed from [pngquant.org]https://pngquant.org/
28
+
27
29
  Or install the utilities via homebrew:
28
30
 
29
31
  ```bash
30
- $ brew install optipng jpegoptim gifsicle
32
+ $ brew install optipng jpegoptim gifsicle pngquant
31
33
  ```
32
34
 
33
35
  Then add this line to your application's Gemfile:
@@ -56,6 +58,13 @@ performs PNG integrity checks and corrections.
56
58
  ImageOptimizer.new('path/to/file.png').optimize
57
59
  ```
58
60
 
61
+ Pngquant is a command-line utility and a library for lossy compression of PNG images.
62
+ The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency. Generated images are compatible with all modern web browsers, and have better fallback in IE6 than 24-bit PNGs.
63
+
64
+ ```ruby
65
+ PNGQuantOptimizer.new('path/to/file.png').optimize
66
+ ```
67
+
59
68
  #### Optimize JPEG formats:
60
69
 
61
70
  jpegoptim provides lossless optimization for JPEG files based on optimizing the Huffman tables.
@@ -107,6 +116,10 @@ optimizer will ignore the value.
107
116
  ImageOptimizer.new('path/to/file.png', level: 3).optimize
108
117
  ```
109
118
 
119
+ Pngquant is called with the '--skip-if-larger', '--speed 1','--force', '--verbose', '--ext .png' flags.
120
+ This runs pngquant on all png files in the current directory and subdirectory and optimized them in place. Flag '--skip-if-larger' skips images which are smaller. Flag '--ext .png' set custom extension (suffix) for output filename. By default -or8.png or -fs8.png is used.
121
+
122
+
110
123
  ##### Don't Remove metadata from PNG
111
124
 
112
125
  By default, `optipng` is called with the `-strip all` flag, which removes all the
@@ -0,0 +1 @@
1
+ fe9e49e0b6c275d15ced45c3b860ec8cf1c1379278a12d12f1fd8aa10641911ff86715f3f9f8603e4e2a93c2815b6c396d252b0c17e49dcf54584803237a9feb
@@ -4,6 +4,7 @@ require 'image_optimizer/image_optimizer_base'
4
4
  require 'image_optimizer/jpeg_optimizer'
5
5
  require 'image_optimizer/png_optimizer'
6
6
  require 'image_optimizer/gif_optimizer'
7
+ require 'image_optimizer/pngquant_optimizer'
7
8
 
8
9
  class ImageOptimizer
9
10
  include Shell
@@ -18,6 +19,7 @@ class ImageOptimizer
18
19
  identify_format if options[:identify]
19
20
  JPEGOptimizer.new(path, options).optimize
20
21
  PNGOptimizer.new(path, options).optimize
22
+ PNGQuantOptimizer.new(path, options).optimize
21
23
  GIFOptimizer.new(path, options).optimize
22
24
  end
23
25
 
@@ -0,0 +1,31 @@
1
+ class ImageOptimizer
2
+ class PNGQuantOptimizer < ImageOptimizerBase
3
+
4
+ private
5
+
6
+ def command_options
7
+ flags = ['--skip-if-larger', '--speed 1',
8
+ '--force', '--verbose', '--ext .png']
9
+ flags << quantity
10
+ flags << path
11
+ end
12
+
13
+ def quantity
14
+ return "--quality 100" unless (0..100).include?(options[:quality])
15
+ "--quality #{options[:quality]}"
16
+ end
17
+
18
+ def extensions
19
+ %w[png]
20
+ end
21
+
22
+ def type
23
+ 'png'
24
+ end
25
+
26
+ def bin_name
27
+ 'pngquant'
28
+ end
29
+
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  class ImageOptimizer
2
- VERSION = '1.6.1'
2
+ VERSION = '1.7.0'
3
3
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe ImageOptimizer::PNGQuantOptimizer do
4
+ describe '#optimize' do
5
+ let(:options) { {} }
6
+ let(:pngquant_optimizer) { ImageOptimizer::PNGQuantOptimizer.new('/path/to/file.png', options) }
7
+ after { ImageOptimizer::PNGQuantOptimizer.instance_variable_set(:@bin, nil) }
8
+ subject { pngquant_optimizer.optimize }
9
+
10
+ context 'pngquant optimizing utility is installed' do
11
+ before do
12
+ allow(ImageOptimizer::PNGQuantOptimizer).to receive(:which).and_return('/usr/local/bin/pngquant')
13
+ end
14
+
15
+ it 'optimizes the png' do
16
+ optimizer_options = %w[--skip-if-larger --speed\ 1 --force --verbose --ext\ .png --quality\ 100 /path/to/file.png]
17
+ expect(pngquant_optimizer).to receive(:system).with('/usr/local/bin/pngquant', *optimizer_options)
18
+ subject
19
+ end
20
+
21
+ context 'ENV variable path to pngquant' do
22
+ let(:image_pngquant_bin_path) { '/app/vendor/bundle/ruby/2.0.0/gems/image_pngquant_bin-0.0.2/bin/pngquant' }
23
+ before do
24
+ ENV['PNGQUANT_BIN'] = image_pngquant_bin_path
25
+ end
26
+ after do
27
+ ENV['PNGQUANT_BIN'] = nil
28
+ end
29
+
30
+ it 'should optimize using the given path' do
31
+ optimizer_options = %w[--skip-if-larger --speed\ 1 --force --verbose --ext\ .png --quality\ 100 /path/to/file.png]
32
+ expect(pngquant_optimizer).to receive(:system).with(image_pngquant_bin_path, *optimizer_options)
33
+ subject
34
+ end
35
+ end
36
+
37
+ context 'with quality parameter' do
38
+ let(:options) { { :quality => 100 } }
39
+
40
+ it 'optimizes the png with the quality' do
41
+ optimizer_options = %w[--skip-if-larger --speed\ 1 --force --verbose --ext\ .png --quality\ 100 /path/to/file.png]
42
+ expect(pngquant_optimizer).to receive(:system).with('/usr/local/bin/pngquant', *optimizer_options)
43
+ subject
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'optimizing utility is not installed' do
49
+ before do
50
+ allow(ImageOptimizer::PNGQuantOptimizer).to receive(:which).and_return(nil)
51
+ end
52
+
53
+ it 'warns the user if the png' do
54
+ expect(pngquant_optimizer).to receive(:warn).with('Attempting to optimize a png without pngquant installed. Skipping...')
55
+ subject
56
+ end
57
+ end
58
+ end
59
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_optimizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Tescher
@@ -30,7 +30,7 @@ cert_chain:
30
30
  8lVFrLvGNGPCLQmEf498hBYT99EVYiuiI0F7YlTmBdzL1uwTMk5le/b0NguYdSJ7
31
31
  qKlUP9usSwMVc+qmaOg1EYfPGYvt63qS
32
32
  -----END CERTIFICATE-----
33
- date: 2016-10-06 00:00:00.000000000 Z
33
+ date: 2016-11-15 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rspec
@@ -127,17 +127,20 @@ files:
127
127
  - checksum/image_optimizer-1.5.0.gem.sha512
128
128
  - checksum/image_optimizer-1.6.0.gem.sha512
129
129
  - checksum/image_optimizer-1.6.1.gem.sha512
130
+ - checksum/image_optimizer-1.7.0.gem.sha512
130
131
  - image_optimizer.gemspec
131
132
  - lib/image_optimizer.rb
132
133
  - lib/image_optimizer/gif_optimizer.rb
133
134
  - lib/image_optimizer/image_optimizer_base.rb
134
135
  - lib/image_optimizer/jpeg_optimizer.rb
135
136
  - lib/image_optimizer/png_optimizer.rb
137
+ - lib/image_optimizer/pngquant_optimizer.rb
136
138
  - lib/image_optimizer/shell.rb
137
139
  - lib/image_optimizer/version.rb
138
140
  - spec/image_optimizer/gif_optimizer_spec.rb
139
141
  - spec/image_optimizer/jpeg_optimizer_spec.rb
140
142
  - spec/image_optimizer/png_optimizer_spec.rb
143
+ - spec/image_optimizer/pngquant_optimizer_spec.rb
141
144
  - spec/image_optimizer/shell_spec.rb
142
145
  - spec/image_optimizer/version_spec.rb
143
146
  - spec/image_optimizer_spec.rb
@@ -170,6 +173,7 @@ test_files:
170
173
  - spec/image_optimizer/gif_optimizer_spec.rb
171
174
  - spec/image_optimizer/jpeg_optimizer_spec.rb
172
175
  - spec/image_optimizer/png_optimizer_spec.rb
176
+ - spec/image_optimizer/pngquant_optimizer_spec.rb
173
177
  - spec/image_optimizer/shell_spec.rb
174
178
  - spec/image_optimizer/version_spec.rb
175
179
  - spec/image_optimizer_spec.rb
metadata.gz.sig CHANGED
Binary file