piet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in piet.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ piet (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ ZenTest (4.5.0)
10
+ diff-lcs (1.1.3)
11
+ rspec (2.7.0)
12
+ rspec-core (~> 2.7.0)
13
+ rspec-expectations (~> 2.7.0)
14
+ rspec-mocks (~> 2.7.0)
15
+ rspec-core (2.7.1)
16
+ rspec-expectations (2.7.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.7.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ ZenTest
25
+ piet!
26
+ rspec
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ Piet
2
+ ======
3
+
4
+ Description
5
+ -----------
6
+
7
+ Piet is a gem that optimizes an image stored in a file, and it has
8
+ integration with CarrierWave uploaders.
9
+
10
+ This gem is named after the minimal Dutch painter Piet Mondrian.
11
+
12
+ [![Build Status](https://secure.travis-ci.org/albertbellonch/piet.png)](http://travis-ci.org/albertbellonch/piet)
13
+
14
+ Installation
15
+ ------------
16
+
17
+ This gem requires two image optimization utilities: **optipng** and
18
+ **jpegoptim**, available in various platforms such as Unix or Windows.
19
+ You can install them by following the instructions on each authors'
20
+ page:
21
+
22
+ * Installation for [optipng](http://optipng.sourceforge.net/)
23
+ * Installation for [jpegoptim](http://freecode.com/projects/jpegoptim)
24
+
25
+ After installing both utils, simply install the gem:
26
+
27
+ gem install piet
28
+
29
+ Usage
30
+ -----
31
+
32
+ You simply require the gem
33
+
34
+ require 'piet'
35
+
36
+ and then call the **optimize** method:
37
+
38
+ Piet.optimize(path, opts)
39
+
40
+ The options are:
41
+
42
+ * **verbose**: Whether you want to get the output of the command or not. It is interpreted as a Boolean value. Default: false.
43
+
44
+
45
+ CarrierWave integration
46
+ -----------------------
47
+
48
+ As stated before, Piet can be integrated into CarrierWave uploaders.
49
+ This way, you can optimize the original image or a version
50
+
51
+ Examples
52
+ --------
53
+
54
+ * Simply Optimizing
55
+
56
+ Piet.optimize('/my/wonderful/pics/piggy.png')
57
+
58
+ Piet.optimize('/my/wonderful/pics/pony.jpg')
59
+
60
+ would optimize those PNG and JPEG files but ouput nothing.
61
+
62
+ * Optimizing PNG and getting feedback
63
+
64
+ Piet.optimize('/my/wonderful/pics/piggy.png', :verbose => true)
65
+
66
+ would optimize that PNG file and ouput something similar to this one:
67
+
68
+ ** Processing: piggy.png
69
+ 340x340 pixels, 4x8 bits/pixel, RGB+alpha
70
+ Input IDAT size = 157369 bytes
71
+ Input file size = 157426 bytes
72
+
73
+ Trying:
74
+ zc = 9 zm = 9 zs = 0 f = 1 IDAT size = 156966
75
+ zc = 9 zm = 8 zs = 0 f = 1 IDAT size = 156932
76
+
77
+ Selecting parameters:
78
+ zc = 9 zm = 8 zs = 0 f = 1 IDAT size = 156932
79
+
80
+ Output IDAT size = 156932 bytes (437 bytes decrease)
81
+ Output file size = 156989 bytes (437 bytes = 0.28% decrease)
82
+
83
+ * Optimizing JPEG and getting feedback
84
+
85
+ Piet.optimize('/my/wonderful/pics/pony.jpg', :verbose => true)
86
+
87
+ would optimize that JPEG file and ouput similar to this one:
88
+
89
+ /my/wonderful/pics/pony.jpg 235x314 24bit JFIF [OK] 15305 --> 13012 bytes (14.98%), optimized.
90
+
91
+ TODO
92
+ ----
93
+
94
+ * Support for GIFs
95
+ * Binary tool for optimizing a file
96
+ * Add some testing!
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,10 @@
1
+ module Piet
2
+ module CarrierWaveExtension
3
+ def optimize
4
+ manipulate! do |img|
5
+ Piet.optimize(img.path)
6
+ img
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Piet
2
+ VERSION = "0.1.0"
3
+ end
data/lib/piet.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'piet/carrierwave_extension'
2
+
3
+ module Piet
4
+ class << self
5
+ VALID_EXTS = %w{ png jpg jpeg }
6
+
7
+ def optimize(path, opts={})
8
+ output = optimize_for(path, opts)
9
+ puts output if opts[:verbose]
10
+ true
11
+ end
12
+
13
+ private
14
+
15
+ def optimize_for(path, opts)
16
+ case extension(path)
17
+ when "png" then optimize_png(path, opts)
18
+ when "jpg", "jpeg" then optimize_jpg(path, opts)
19
+ end
20
+ end
21
+
22
+ def extension(path)
23
+ path.split(".").last.downcase
24
+ end
25
+
26
+ def optimize_png(path, opts)
27
+ vo = opts[:verbose] ? "-v" : "-quiet"
28
+ `optipng -o7 #{vo} #{path}`
29
+ end
30
+
31
+ def optimize_jpg(path, opts)
32
+ vo = opts[:verbose] ? "-v" : "-q"
33
+ `jpegoptim -f --strip-all #{vo} #{path}`
34
+ end
35
+ end
36
+ end
data/piet.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "piet/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "piet"
7
+ s.version = Piet::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Albert Bellonch"]
10
+ s.email = ["albert@itnig.net"]
11
+ s.homepage = "http://itnig.net"
12
+ s.summary = %q{An image optimizer}
13
+ s.description = %q{-}
14
+
15
+ s.rubyforge_project = "piet"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.require_paths = ["lib"]
20
+ s.add_development_dependency "rspec"
21
+ s.add_development_dependency "ZenTest"
22
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1 @@
1
+ require 'piet'
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: piet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Albert Bellonch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70360654319140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70360654319140
25
+ - !ruby/object:Gem::Dependency
26
+ name: ZenTest
27
+ requirement: &70360654318340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70360654318340
36
+ description: ! '-'
37
+ email:
38
+ - albert@itnig.net
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - Gemfile
44
+ - Gemfile.lock
45
+ - README.md
46
+ - Rakefile
47
+ - lib/piet.rb
48
+ - lib/piet/carrierwave_extension.rb
49
+ - lib/piet/version.rb
50
+ - piet.gemspec
51
+ - spec/integration/piet_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: http://itnig.net
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project: piet
73
+ rubygems_version: 1.8.10
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: An image optimizer
77
+ test_files:
78
+ - spec/integration/piet_spec.rb
79
+ - spec/spec_helper.rb