tinypng 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/tinypng +27 -0
- data/lib/tinypng.rb +6 -0
- data/lib/tinypng/client.rb +25 -0
- data/lib/tinypng/exception.rb +3 -0
- data/lib/tinypng/image.rb +32 -0
- data/lib/tinypng/version.rb +3 -0
- data/tinypng.gemspec +21 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Benjamin Manns
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# TinyPNG
|
|
2
|
+
|
|
3
|
+
TinyPNG is a simple API client for TinyPNG.org, which compresses your PNG images by 50-70% while preserving full transparency.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'tinypng'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install tinypng
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Use the Ruby API in your programs:
|
|
22
|
+
|
|
23
|
+
require 'tinypng'
|
|
24
|
+
image_file = File.open(image_file_name)
|
|
25
|
+
client = TinyPNG::Client.new
|
|
26
|
+
image = client.shrink(image_file.read)
|
|
27
|
+
image.input # => {"size"=>1234}
|
|
28
|
+
image.output # => {"depth"=>8, "size"=>567, "ratio"=>0.459, "url"=>"http://tinypng.org/api/shrink/out/example.png"}
|
|
29
|
+
image.to_file # => #<File:/tmp/tinypng20120910-5552-aturxh.png>
|
|
30
|
+
|
|
31
|
+
Or use the command line to shrink your images:
|
|
32
|
+
|
|
33
|
+
tinypng mybigimage.png myshrunkenimage.png
|
|
34
|
+
|
|
35
|
+
## Contributing
|
|
36
|
+
|
|
37
|
+
1. Fork it
|
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/tinypng
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
def usage
|
|
4
|
+
puts "tinypng input.png output.png"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
input = ARGV[0]
|
|
8
|
+
output = ARGV[1]
|
|
9
|
+
|
|
10
|
+
unless input && output
|
|
11
|
+
usage
|
|
12
|
+
exit 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
$LOAD_PATH << File.expand_path(File.join(__FILE__, '../../lib'))
|
|
16
|
+
require 'tinypng'
|
|
17
|
+
|
|
18
|
+
client = TinyPNG::Client.new
|
|
19
|
+
begin
|
|
20
|
+
image = client.shrink(File.open(input) { |file| file.read })
|
|
21
|
+
rescue TinyPNG::Exception => e
|
|
22
|
+
puts e
|
|
23
|
+
exit 1
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require 'fileutils'
|
|
27
|
+
FileUtils.cp(image.to_file, output)
|
data/lib/tinypng.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
require 'tinypng/image'
|
|
4
|
+
require 'tinypng/exception'
|
|
5
|
+
|
|
6
|
+
module TinyPNG
|
|
7
|
+
class Client
|
|
8
|
+
include HTTParty
|
|
9
|
+
base_uri 'http://tinypng.org/api'
|
|
10
|
+
|
|
11
|
+
def shrink image
|
|
12
|
+
begin
|
|
13
|
+
response = self.class.post('/shrink', body: image).parsed_response
|
|
14
|
+
rescue => e
|
|
15
|
+
raise Exception.new("Network error: #{e}")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
if response['code']
|
|
19
|
+
raise Exception.new("#{response['code']}: #{response['message']}")
|
|
20
|
+
else
|
|
21
|
+
Image.new(response)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'tempfile'
|
|
2
|
+
|
|
3
|
+
require 'tinypng/client'
|
|
4
|
+
|
|
5
|
+
module TinyPNG
|
|
6
|
+
class Image
|
|
7
|
+
def initialize params={}
|
|
8
|
+
@params = params
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def input
|
|
12
|
+
@params['input']
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def output
|
|
16
|
+
@params['output']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_file
|
|
20
|
+
Tempfile.new(['tinypng', '.png']).tap do |file|
|
|
21
|
+
begin
|
|
22
|
+
image_response = TinyPNG::Client.get(output['url'])
|
|
23
|
+
rescue => e
|
|
24
|
+
raise Exception.new("Network error: #{e}")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
file.write image_response
|
|
28
|
+
file.rewind
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/tinypng.gemspec
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'tinypng/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |gem|
|
|
7
|
+
gem.name = "tinypng"
|
|
8
|
+
gem.version = TinyPNG::VERSION
|
|
9
|
+
gem.authors = ["Benjamin Manns"]
|
|
10
|
+
gem.email = ["benmanns@gmail.com"]
|
|
11
|
+
gem.description = %q{Simple API client for TinyPNG.org.}
|
|
12
|
+
gem.summary = %q{TinyPNG is a simple API client for TinyPNG.org, which compresses your PNG images by 50-70% while preserving full transparency.}
|
|
13
|
+
gem.homepage = 'http://github.com/benmanns/tinypng'
|
|
14
|
+
|
|
15
|
+
gem.add_dependency 'httparty'
|
|
16
|
+
|
|
17
|
+
gem.files = `git ls-files`.split($/)
|
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
gem.require_paths = ["lib"]
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tinypng
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Benjamin Manns
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: httparty
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
description: Simple API client for TinyPNG.org.
|
|
31
|
+
email:
|
|
32
|
+
- benmanns@gmail.com
|
|
33
|
+
executables:
|
|
34
|
+
- tinypng
|
|
35
|
+
extensions: []
|
|
36
|
+
extra_rdoc_files: []
|
|
37
|
+
files:
|
|
38
|
+
- .gitignore
|
|
39
|
+
- Gemfile
|
|
40
|
+
- LICENSE.txt
|
|
41
|
+
- README.md
|
|
42
|
+
- Rakefile
|
|
43
|
+
- bin/tinypng
|
|
44
|
+
- lib/tinypng.rb
|
|
45
|
+
- lib/tinypng/client.rb
|
|
46
|
+
- lib/tinypng/exception.rb
|
|
47
|
+
- lib/tinypng/image.rb
|
|
48
|
+
- lib/tinypng/version.rb
|
|
49
|
+
- tinypng.gemspec
|
|
50
|
+
homepage: http://github.com/benmanns/tinypng
|
|
51
|
+
licenses: []
|
|
52
|
+
post_install_message:
|
|
53
|
+
rdoc_options: []
|
|
54
|
+
require_paths:
|
|
55
|
+
- lib
|
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
|
+
none: false
|
|
64
|
+
requirements:
|
|
65
|
+
- - ! '>='
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
requirements: []
|
|
69
|
+
rubyforge_project:
|
|
70
|
+
rubygems_version: 1.8.24
|
|
71
|
+
signing_key:
|
|
72
|
+
specification_version: 3
|
|
73
|
+
summary: TinyPNG is a simple API client for TinyPNG.org, which compresses your PNG
|
|
74
|
+
images by 50-70% while preserving full transparency.
|
|
75
|
+
test_files: []
|
|
76
|
+
has_rdoc:
|