bloatpng 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.travis.yml +3 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/bloat +16 -0
- data/bloatpng.gemspec +66 -0
- data/data/smiley-face.png +0 -0
- data/lib/bloatpng.rb +45 -0
- data/test/helper.rb +18 -0
- data/test/test_bloatpng.rb +32 -0
- metadata +146 -0
data/.document
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.10)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
bourne (1.1.2)
|
8
|
+
mocha (= 0.10.5)
|
9
|
+
digest-crc (0.3.0)
|
10
|
+
git (1.2.5)
|
11
|
+
i18n (0.6.1)
|
12
|
+
jeweler (1.8.4)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.7.6)
|
18
|
+
metaclass (0.0.1)
|
19
|
+
mocha (0.10.5)
|
20
|
+
metaclass (~> 0.0.1)
|
21
|
+
multi_json (1.5.0)
|
22
|
+
rake (10.0.3)
|
23
|
+
rdoc (3.12)
|
24
|
+
json (~> 1.4)
|
25
|
+
shoulda (3.3.2)
|
26
|
+
shoulda-context (~> 1.0.1)
|
27
|
+
shoulda-matchers (~> 1.4.1)
|
28
|
+
shoulda-context (1.0.2)
|
29
|
+
shoulda-matchers (1.4.2)
|
30
|
+
activesupport (>= 3.0.0)
|
31
|
+
bourne (~> 1.1.2)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler (>= 1.0.0)
|
38
|
+
digest-crc
|
39
|
+
jeweler (~> 1.8.4)
|
40
|
+
rdoc (~> 3.12)
|
41
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Nate Benes
|
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.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= bloatpng
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to bloatpng
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Nate Benes. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "bloatpng"
|
17
|
+
gem.homepage = "http://github.com/natebenes/bloatpng"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{Shrinking PNG's is overrated.}
|
20
|
+
gem.description = %Q{There are plenty of tools to make your PNG's smaller. Sometimes bigger is better.}
|
21
|
+
gem.email = "natebenes@gmail.com"
|
22
|
+
gem.authors = ["Nate Benes"]
|
23
|
+
# dependencies defined in Gemfile
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
#require 'rcov/rcovtask'
|
35
|
+
#Rcov::RcovTask.new do |test|
|
36
|
+
# test.libs << 'test'
|
37
|
+
# test.pattern = 'test/**/test_*.rb'
|
38
|
+
# test.verbose = true
|
39
|
+
# test.rcov_opts << '--exclude "gems/*"'
|
40
|
+
#end
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rdoc/task'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "bloatpng #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/bloat
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bloatpng'
|
4
|
+
|
5
|
+
if ARGV[2].nil?
|
6
|
+
puts "Usage:\nbloat INPUT_FILE OUTPUT_FILE KILOBYTES_TO_ADD\n\n"
|
7
|
+
puts "Example:\nbloat happy.png 1024"
|
8
|
+
puts " (this would bloat happy.png by one megabyte)"
|
9
|
+
exit!(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
unless File.exists? ARGV[0]
|
13
|
+
puts "Error: unable to open that file."
|
14
|
+
end
|
15
|
+
|
16
|
+
BloatPNG.bloat(ARGV[0], ARGV[1], ARGV[2] * 1024)
|
data/bloatpng.gemspec
ADDED
@@ -0,0 +1,66 @@
|
|
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
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "bloatpng"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nate Benes"]
|
12
|
+
s.date = "2013-01-07"
|
13
|
+
s.description = "There are plenty of tools to make your PNG's smaller. Sometimes bigger is better."
|
14
|
+
s.email = "natebenes@gmail.com"
|
15
|
+
s.executables = ["bloat"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".travis.yml",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/bloat",
|
30
|
+
"bloatpng.gemspec",
|
31
|
+
"data/smiley-face.png",
|
32
|
+
"lib/bloatpng.rb",
|
33
|
+
"test/helper.rb",
|
34
|
+
"test/test_bloatpng.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/natebenes/bloatpng"
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = "1.8.24"
|
40
|
+
s.summary = "Shrinking PNG's is overrated."
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
|
+
s.add_development_dependency(%q<digest-crc>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
+
s.add_dependency(%q<digest-crc>, [">= 0"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
61
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
63
|
+
s.add_dependency(%q<digest-crc>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
Binary file
|
data/lib/bloatpng.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'digest/crc32'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
class BloatPNG
|
5
|
+
|
6
|
+
# "Bloats" a PNG file by adding random
|
7
|
+
# data in the form of text elements
|
8
|
+
def self.bloat(input, output, size=256)
|
9
|
+
if(size < 20)
|
10
|
+
raise NeedsMoreBloatException
|
11
|
+
end
|
12
|
+
n = size - 32 - Math.log2(size).to_i
|
13
|
+
key = SecureRandom.hex(15)
|
14
|
+
text = SecureRandom.hex(n)[1..n]
|
15
|
+
self.insert_text_element(input, output, key, text)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# see: http://www.w3.org/TR/PNG/#11tEXt
|
21
|
+
def self.insert_text_element(input_file, output_file, key, text)
|
22
|
+
png = ""
|
23
|
+
File.open(input_file, 'rb') do |f|
|
24
|
+
png = f.read
|
25
|
+
end
|
26
|
+
chunk = create_text_element(key, text)
|
27
|
+
File.open(output_file, 'wb') do |f|
|
28
|
+
f.write(add_chunk_to_png(chunk, png))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.create_text_element(key, text)
|
33
|
+
raise KeySizeError if key.length > 79
|
34
|
+
chunk_type = "tEXt"
|
35
|
+
chunk_data = key.gsub("\0", " ") + "\0" + text.gsub("\0", " ") # null-separated
|
36
|
+
crc = [Digest::CRC32.checksum(chunk_type + chunk_data)].pack('N')
|
37
|
+
len = [chunk_data.length].pack('N')
|
38
|
+
return len + chunk_type + chunk_data + crc
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.add_chunk_to_png(chunk, png)
|
42
|
+
len = png.length
|
43
|
+
return png[0,len-12] + chunk + png[len-12,12]
|
44
|
+
end
|
45
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'bloatpng'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestBloatpng < Test::Unit::TestCase
|
4
|
+
context "bloatpng" do
|
5
|
+
setup do
|
6
|
+
create_test_data!
|
7
|
+
at_exit do
|
8
|
+
clean_up!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_test_data!
|
13
|
+
BloatPNG.bloat(File.join('data', 'smiley-face.png'), File.join('data', 'smiley-fat-face.png'), 1024*1024)
|
14
|
+
end
|
15
|
+
|
16
|
+
def clean_up!
|
17
|
+
if File.exists? File.join('data', 'smiley-fat-face.png')
|
18
|
+
File.delete(File.join('data', 'smiley-fat-face.png'))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "create an output file" do
|
23
|
+
assert File.exists?(File.join('data', 'smiley-fat-face.png'))
|
24
|
+
end
|
25
|
+
|
26
|
+
should "make an output file of the correct size" do
|
27
|
+
assert_equal File.size?(File.join('data', 'smiley-fat-face.png')), 1059390
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bloatpng
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nate Benes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
none: false
|
28
|
+
type: :development
|
29
|
+
name: shoulda
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
prerelease: false
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3.12'
|
37
|
+
none: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '3.12'
|
43
|
+
none: false
|
44
|
+
type: :development
|
45
|
+
name: rdoc
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
prerelease: false
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.0.0
|
53
|
+
none: false
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.0.0
|
59
|
+
none: false
|
60
|
+
type: :development
|
61
|
+
name: bundler
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
prerelease: false
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.8.4
|
69
|
+
none: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.8.4
|
75
|
+
none: false
|
76
|
+
type: :development
|
77
|
+
name: jeweler
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
prerelease: false
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
none: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
none: false
|
92
|
+
type: :development
|
93
|
+
name: digest-crc
|
94
|
+
description: There are plenty of tools to make your PNG's smaller. Sometimes bigger
|
95
|
+
is better.
|
96
|
+
email: natebenes@gmail.com
|
97
|
+
executables:
|
98
|
+
- bloat
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files:
|
101
|
+
- LICENSE.txt
|
102
|
+
- README.rdoc
|
103
|
+
files:
|
104
|
+
- .document
|
105
|
+
- .travis.yml
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.rdoc
|
110
|
+
- Rakefile
|
111
|
+
- VERSION
|
112
|
+
- bin/bloat
|
113
|
+
- bloatpng.gemspec
|
114
|
+
- data/smiley-face.png
|
115
|
+
- lib/bloatpng.rb
|
116
|
+
- test/helper.rb
|
117
|
+
- test/test_bloatpng.rb
|
118
|
+
homepage: http://github.com/natebenes/bloatpng
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
hash: -4058835666247743217
|
133
|
+
none: false
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
none: false
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 1.8.24
|
143
|
+
signing_key:
|
144
|
+
specification_version: 3
|
145
|
+
summary: Shrinking PNG's is overrated.
|
146
|
+
test_files: []
|