gif_optimizer 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.md +46 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/gif_optimizer.gemspec +65 -0
- data/lib/gif_optimizer.rb +2 -0
- data/lib/gif_optimizer/optimizer.rb +47 -0
- data/lib/gif_optimizer/version.rb +3 -0
- data/spec/gif_optimizer_spec.rb +27 -0
- data/spec/spec_helper.rb +29 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b5fe4863e6cd6971c83fe2ac800c27aaabc56d5
|
4
|
+
data.tar.gz: 875f96361f3b6835a9095c5e31b73faa20ee6f13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 415724136b4d1e391af01faac64304068fa51208a5555a5a8bfc235dea00959ff61b4b2634b44774b029115de05f82bdc79eb263a0c618a899733eee5ed5f5ee
|
7
|
+
data.tar.gz: 4f5dca78f7f69f051d59feba4f7466c5d67bc4fe49d2e932c4a9bd830b03ef7956d179be2ad163dc1055763ae140496a57a7f16344c8796b2d93e51f03a02d83
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "jeweler", "~> 2.0.1"
|
13
|
+
gem "simplecov", ">= 0"
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Rubem Nakamura
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# GifOptimizer
|
2
|
+
|
3
|
+
This gem allows you to simply optimize gifs via gifsicle.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
##### This gem uses the following utilities for optimizing gifs:
|
8
|
+
|
9
|
+
1. gifsicle, which can be found and installed from [this link](http://www.lcdf.org/gifsicle/)
|
10
|
+
|
11
|
+
Or install the utilities via homebrew:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
$ brew install gifsicle
|
15
|
+
```
|
16
|
+
|
17
|
+
Then add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'gif_optimizer'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ bundle
|
25
|
+
```
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
```bash
|
29
|
+
$ gem install gif_optimizer
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
#### Optimize:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
GifOptimizer.Optimizer('path/to/file.gif').optimize
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
6
|
+
require 'gif_optimizer'
|
7
|
+
|
8
|
+
begin
|
9
|
+
Bundler.setup(:default, :development)
|
10
|
+
rescue Bundler::BundlerError => e
|
11
|
+
$stderr.puts e.message
|
12
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
13
|
+
exit e.status_code
|
14
|
+
end
|
15
|
+
require 'rake'
|
16
|
+
|
17
|
+
require 'jeweler'
|
18
|
+
Jeweler::Tasks.new do |gem|
|
19
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
20
|
+
gem.name = "gif_optimizer"
|
21
|
+
gem.homepage = "http://github.com/rubemz/gif_optimizer"
|
22
|
+
gem.license = "MIT"
|
23
|
+
gem.summary = "optimize gifs!"
|
24
|
+
gem.description = %Q{optmize gifs!}
|
25
|
+
gem.email = "rubem.nakamura@gmail.com"
|
26
|
+
gem.authors = ["Rubem Nakamura"]
|
27
|
+
# dependencies defined in Gemfile
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rspec/core'
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
34
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Code coverage detail"
|
38
|
+
task :simplecov do
|
39
|
+
ENV['COVERAGE'] = "true"
|
40
|
+
Rake::Task['spec'].execute
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "gif_optimizer #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: gif_optimizer 0.1.2 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "gif_optimizer"
|
9
|
+
s.version = "0.1.2"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ["Rubem Nakamura"]
|
13
|
+
s.date = "2014-03-10"
|
14
|
+
s.description = "optmize gifs!"
|
15
|
+
s.email = "rubem.nakamura@gmail.com"
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"gif_optimizer.gemspec",
|
29
|
+
"lib/gif_optimizer.rb",
|
30
|
+
"lib/gif_optimizer/optimizer.rb",
|
31
|
+
"lib/gif_optimizer/version.rb",
|
32
|
+
"spec/gif_optimizer_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/rubemz/gif_optimizer"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "2.1.2"
|
39
|
+
s.summary = "optimize gifs!"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 4
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
46
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
49
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
52
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
55
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
59
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
62
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module GifOptimizer
|
2
|
+
class Optimizer
|
3
|
+
attr_reader :path, :options
|
4
|
+
|
5
|
+
def initialize(path, options = {})
|
6
|
+
@path = path
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def optimize
|
11
|
+
return unless gif_format?
|
12
|
+
|
13
|
+
if optimizer_present?
|
14
|
+
optimize_gif
|
15
|
+
else
|
16
|
+
warn 'Attempting to optimize a gif without gifsicle installed. Skipping...'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def gif_format?
|
23
|
+
['gif'].include? extension(path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def extension(path)
|
27
|
+
path.split('.').last.downcase
|
28
|
+
end
|
29
|
+
|
30
|
+
def optimize_gif
|
31
|
+
system(gif_optimizer_bin, *command_options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def command_options
|
35
|
+
flags = ['-b', '-O3']
|
36
|
+
flags << path
|
37
|
+
end
|
38
|
+
|
39
|
+
def optimizer_present?
|
40
|
+
!gif_optimizer_bin.nil? && !gif_optimizer_bin.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
def gif_optimizer_bin
|
44
|
+
@gif_optimizer_bin ||= ENV['GIFSICLE_BIN'] || `which gifsicle`.strip
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe GifOptimizer::Optimizer do
|
4
|
+
describe '#optimize' do
|
5
|
+
let(:gif_optimizer) { GifOptimizer::Optimizer.new('/path/to/file.gif') }
|
6
|
+
let(:optimizer_options) { %w[-b -O3 /path/to/file.gif] }
|
7
|
+
|
8
|
+
it 'optimizes the gif' do
|
9
|
+
gif_optimizer.stub(:gif_optimizer_bin => '/usr/local/bin/gifsicle')
|
10
|
+
gif_optimizer.should_receive(:system).with('/usr/local/bin/gifsicle', *optimizer_options)
|
11
|
+
gif_optimizer.optimize
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'warns the user if the gif optimizing utility is not installed' do
|
15
|
+
gif_optimizer.stub(:gif_optimizer_bin => '')
|
16
|
+
gif_optimizer.should_receive(:warn).with('Attempting to optimize a gif without gifsicle installed. Skipping...')
|
17
|
+
gif_optimizer.optimize
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'detects if there is an ENV variable path to gifsicle' do
|
21
|
+
image_optim_gifsicle_bin_path = '/app/vendor/bundle/ruby/2.0.0/gems/image_optim_bin-0.0.2/bin/gifsicle'
|
22
|
+
ENV['GIFSICLE_BIN'] = image_optim_gifsicle_bin_path
|
23
|
+
gif_optimizer.should_receive(:system).with(image_optim_gifsicle_bin_path, *optimizer_options)
|
24
|
+
gif_optimizer.optimize
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require 'rspec'
|
21
|
+
require 'gif_optimizer'
|
22
|
+
|
23
|
+
# Requires supporting files with custom matchers and macros, etc,
|
24
|
+
# in ./support/ and its subdirectories.
|
25
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gif_optimizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rubem Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.8.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: optmize gifs!
|
84
|
+
email: rubem.nakamura@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- .rspec
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- gif_optimizer.gemspec
|
99
|
+
- lib/gif_optimizer.rb
|
100
|
+
- lib/gif_optimizer/optimizer.rb
|
101
|
+
- lib/gif_optimizer/version.rb
|
102
|
+
- spec/gif_optimizer_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: http://github.com/rubemz/gif_optimizer
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.1.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: optimize gifs!
|
128
|
+
test_files: []
|