image_optimizer 1.5.0 → 1.6.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: fe0ce5556db01889c9fef089fed908d4f1b79bc2
4
- data.tar.gz: ceedd80eaf3103531acb0fc65294f8a490a6d0ec
3
+ metadata.gz: bc1965ff20a12b495be3c4b0bf4e312e4a81eddb
4
+ data.tar.gz: 1df870fc21e4a638420c7df2fad7a16b7d151d1b
5
5
  SHA512:
6
- metadata.gz: a97195d6d3deff29e16156d0844f56590175c3b4aa0307eebd824a532b17e8bd8a6efad00be116bcc66e80fb87687b1cb6964882ebed81a47756e79fd523f934
7
- data.tar.gz: 51237df0a72c67bbb412a27d3a7851728d84ea5333ceb1ab91286125c82f85a9af7a7eafdb1e495496f3762853948d38e9af49314fbb4ed7509447965f7f5f77
6
+ metadata.gz: 9bbb9fc93085a14e99ea772bdf15aa802f0f541f6e3dea65d669b5595f67276c1bb14d2175e87aeac08e6af3ab4c43fcc55e3005ea83f2432312954552451c95
7
+ data.tar.gz: f2e8eec48adb796e0089d34188820aa1f75da6cbda3af71837b150675e09d5df67e16eff7efed256e4229ca128695f94f6d5b838efdca02f3628be3502217fb2
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -22,10 +22,12 @@ Tested against ruby 2.0.x, 2.1.x, 2.2.x, 2.3.x, and ruby-head
22
22
 
23
23
  2. OptiPNG, which can be installed from [sourceforge.net](http://optipng.sourceforge.net/)
24
24
 
25
+ 3. Gifsicle, which can be installed from [www.lcdf.org/gifsicle/](https://www.lcdf.org/gifsicle/)
26
+
25
27
  Or install the utilities via homebrew:
26
28
 
27
29
  ```bash
28
- $ brew install optipng jpegoptim
30
+ $ brew install optipng jpegoptim gifsicle
29
31
  ```
30
32
 
31
33
  Then add this line to your application's Gemfile:
@@ -45,7 +47,7 @@ $ gem install image_optimizer
45
47
 
46
48
  ## Usage
47
49
 
48
- #### Optimize PNG or GIF formats:
50
+ #### Optimize PNG formats:
49
51
 
50
52
  OptiPNG is a PNG optimizer that recompresses image files to a smaller size without losing any information and
51
53
  performs PNG integrity checks and corrections.
@@ -63,6 +65,14 @@ All jpegs will be progressively optimized for a better web experience
63
65
  ImageOptimizer.new('path/to/file.jpg').optimize
64
66
  ```
65
67
 
68
+ #### Optimize GIF formats:
69
+
70
+ Gifsicle is a command-line tool for creating, editing, and getting information about GIF images and animations. This stores only the changed portion of each frame, and can radically shrink your GIFs. You can also use transparency to make them even smaller. Gifsicle’s optimizer is pretty powerful, and usually reduces animations to within a couple bytes of the best commercial optimizers.
71
+
72
+ ```ruby
73
+ ImageOptimizer.new('path/to/file.gif').optimize
74
+ ```
75
+
66
76
  ## Optimization Options
67
77
 
68
78
  ##### Quiet optimization
@@ -109,6 +119,18 @@ You can skip removing the meta data by changing the `strip_metadata` parameter t
109
119
  ImageOptimizer.new('path/to/file.png', strip_metadata: false).optimize
110
120
  ```
111
121
 
122
+ ##### Custom GIF optimization quality
123
+
124
+ By default, `gifsicle` is called with the `-O1` flag, which controls the level of
125
+ optimization. It stores only the changed portion of each image. Other allowed flag are `-O2` (Also uses transparency to shrink the file further), `-O3` (Try several optimization methods , usually slower, sometimes better results)
126
+
127
+ You can pass an optional `level` parameter to change this value. the JPEG
128
+ optimizer will ignore the value.
129
+
130
+ ```ruby
131
+ ImageOptimizer.new('path/to/file.gif', level: 3).optimize
132
+ ```
133
+
112
134
  ##### Use identify
113
135
 
114
136
  Pass an optional `identify` parameter to identify file types using ImageMagick or GraphicsMagick `identify`
data/certs/jtescher.pem CHANGED
@@ -1,21 +1,21 @@
1
1
  -----BEGIN CERTIFICATE-----
2
2
  MIIDdDCCAlygAwIBAgIBATANBgkqhkiG9w0BAQUFADBAMRIwEAYDVQQDDAlqYXRl
3
3
  c2NoZXIxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
4
- bTAeFw0xNjA5MTQyMjMxMjBaFw0xNz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FICATE-----
@@ -0,0 +1 @@
1
+ c1e31ef50556ea85d20d056bb5145879e85fd60a8814d8eb62ffdf6e144d2bdd52c9b718c17e2b9fd14c58a0fdc23dc7a23ae5a6982edcf280ff5eaaf0963189
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ["Julian Tescher"]
10
10
  gem.email = ["jatescher@gmail.com"]
11
11
  gem.description = %q{A simple image optimizer}
12
- gem.summary = %q{Simply optimize images via jpegoptim or OptiPNG}
12
+ gem.summary = %q{Simply optimize images via jpegoptim or OptiPNG or Gifsicle}
13
13
  gem.homepage = "https://github.com/jtescher/image_optimizer"
14
14
  gem.license = 'MIT'
15
15
  gem.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $0 =~ /gem\z/
@@ -0,0 +1,28 @@
1
+ class ImageOptimizer
2
+ class GIFOptimizer < ImageOptimizerBase
3
+
4
+ private
5
+
6
+ def command_options
7
+ flags = %W[-b -O#{level}]
8
+ flags << path
9
+ end
10
+
11
+ def level
12
+ options[:level] || 1
13
+ end
14
+
15
+ def type
16
+ 'gif'
17
+ end
18
+
19
+ def extensions
20
+ %w[gif]
21
+ end
22
+
23
+ def bin_name
24
+ 'gifsicle'
25
+ end
26
+
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  class ImageOptimizer
2
- VERSION = '1.5.0'
2
+ VERSION = '1.6.0'
3
3
  end
@@ -3,6 +3,7 @@ require 'image_optimizer/shell'
3
3
  require 'image_optimizer/image_optimizer_base'
4
4
  require 'image_optimizer/jpeg_optimizer'
5
5
  require 'image_optimizer/png_optimizer'
6
+ require 'image_optimizer/gif_optimizer'
6
7
 
7
8
  class ImageOptimizer
8
9
  include Shell
@@ -17,6 +18,7 @@ class ImageOptimizer
17
18
  identify_format if options[:identify]
18
19
  JPEGOptimizer.new(path, options).optimize
19
20
  PNGOptimizer.new(path, options).optimize
21
+ GIFOptimizer.new(path, options).optimize
20
22
  end
21
23
 
22
24
  private
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe ImageOptimizer::GIFOptimizer do
4
+ describe '#optimize' do
5
+ let(:options) { {} }
6
+ let(:gif_optimizer) { ImageOptimizer::GIFOptimizer.new('/path/to/file.gif', options) }
7
+ after { ImageOptimizer::GIFOptimizer.instance_variable_set(:@bin, nil) }
8
+ subject { gif_optimizer.optimize }
9
+
10
+ context 'with gif optimizing utility installed' do
11
+ before do
12
+ allow(ImageOptimizer::GIFOptimizer).to receive(:which).and_return('/usr/local/bin/gifsicle')
13
+ end
14
+
15
+ it 'optimizes the gif' do
16
+ expect(gif_optimizer).to receive(:system).with('/usr/local/bin/gifsicle', '-b', '-O1', '/path/to/file.gif')
17
+ subject
18
+ end
19
+
20
+ context 'ENV variable path to gifsicle' do
21
+ let(:image_optim_gifsicle_bin_path) { '/app/vendor/bundle/ruby/2.0.0/gems/image_optim_bin-0.0.2/bin/gifsicle' }
22
+ before do
23
+ ENV['GIFSICLE_BIN'] = image_optim_gifsicle_bin_path
24
+ end
25
+ after do
26
+ ENV['GIFSICLE_BIN'] = nil
27
+ end
28
+
29
+ it 'detects if there is an ENV variable path to gifsicle' do
30
+ expect(gif_optimizer).to receive(:system).with(image_optim_gifsicle_bin_path, '-b', '-O1', '/path/to/file.gif')
31
+ subject
32
+ end
33
+ end
34
+
35
+ context 'without optimization parameter' do
36
+ it 'optimizes the gif with level 7 optimization' do
37
+ expect(gif_optimizer).to receive(:system).with('/usr/local/bin/gifsicle', '-b', '-O1', '/path/to/file.gif')
38
+ subject
39
+ end
40
+ end
41
+
42
+ context 'with optimization parameter' do
43
+ let(:options) { { level: 2 } }
44
+ it 'optimizes the gif with the requested optimization level' do
45
+ expect(gif_optimizer).to receive(:system).with('/usr/local/bin/gifsicle', '-b', '-O2', '/path/to/file.gif')
46
+ subject
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ context 'with gif optimizing utility not installed' do
53
+ before do
54
+ allow(ImageOptimizer::GIFOptimizer).to receive(:which).and_return(nil)
55
+ end
56
+
57
+ it 'warns the user' do
58
+ expect(gif_optimizer).to receive(:warn).with('Attempting to optimize a gif without gifsicle installed. Skipping...')
59
+ subject
60
+ end
61
+ end
62
+ end
63
+ end
@@ -7,9 +7,10 @@ describe ImageOptimizer do
7
7
  describe '#optimize' do
8
8
  subject { ImageOptimizer.new(File.join(image_path), options) }
9
9
 
10
- it 'delegates to jpeg and png optimizers' do
10
+ it 'delegates to jpeg, png and gif optimizers' do
11
11
  expect_any_instance_of(ImageOptimizer::JPEGOptimizer).to receive(:optimize)
12
12
  expect_any_instance_of(ImageOptimizer::PNGOptimizer).to receive(:optimize)
13
+ expect_any_instance_of(ImageOptimizer::GIFOptimizer).to receive(:optimize)
13
14
  subject.optimize
14
15
  end
15
16
  end
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- n�pIԇda��VA4�2#}��үG�4򤥆�|�ȍB ��>�;-�p�n]�4��=6���ה����6�!�K�9�Y�#aU�N_-�Ga���>r���E��y1^�A�X���uf ^��WuLL�ڹkxZ�F�ܡ����鎸��P�U���x��ǧ��KO.�� _����)���Y#!��hA
2
- �6^���z#���c�"�D�ACD=D�n����Ό(��0��MjГ�歫;>s����Bg�~6��u��T
1
+ 3+
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.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Tescher
@@ -12,25 +12,25 @@ cert_chain:
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIDdDCCAlygAwIBAgIBATANBgkqhkiG9w0BAQUFADBAMRIwEAYDVQQDDAlqYXRl
14
14
  c2NoZXIxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
15
- bTAeFw0xNjA5MTQyMjMxMjBaFw0xNzA5MTQyMjMxMjBaMEAxEjAQBgNVBAMMCWph
15
+ bTA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016-09-26 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rspec
@@ -125,13 +125,16 @@ files:
125
125
  - checksum/image_optimizer-1.3.0.gem.sha512
126
126
  - checksum/image_optimizer-1.4.0.gem.sha512
127
127
  - checksum/image_optimizer-1.5.0.gem.sha512
128
+ - checksum/image_optimizer-1.6.0.gem.sha512
128
129
  - image_optimizer.gemspec
129
130
  - lib/image_optimizer.rb
131
+ - lib/image_optimizer/gif_optimizer.rb
130
132
  - lib/image_optimizer/image_optimizer_base.rb
131
133
  - lib/image_optimizer/jpeg_optimizer.rb
132
134
  - lib/image_optimizer/png_optimizer.rb
133
135
  - lib/image_optimizer/shell.rb
134
136
  - lib/image_optimizer/version.rb
137
+ - spec/image_optimizer/gif_optimizer_spec.rb
135
138
  - spec/image_optimizer/jpeg_optimizer_spec.rb
136
139
  - spec/image_optimizer/png_optimizer_spec.rb
137
140
  - spec/image_optimizer/shell_spec.rb
@@ -158,11 +161,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
161
  version: '0'
159
162
  requirements: []
160
163
  rubyforge_project:
161
- rubygems_version: 2.6.6
164
+ rubygems_version: 2.5.1
162
165
  signing_key:
163
166
  specification_version: 4
164
- summary: Simply optimize images via jpegoptim or OptiPNG
167
+ summary: Simply optimize images via jpegoptim or OptiPNG or Gifsicle
165
168
  test_files:
169
+ - spec/image_optimizer/gif_optimizer_spec.rb
166
170
  - spec/image_optimizer/jpeg_optimizer_spec.rb
167
171
  - spec/image_optimizer/png_optimizer_spec.rb
168
172
  - spec/image_optimizer/shell_spec.rb
metadata.gz.sig CHANGED
Binary file