photile 0.1.0.pre
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 +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +62 -0
- data/Rakefile +23 -0
- data/bin/photile +46 -0
- data/lib/photile.rb +63 -0
- data/lib/photile/translator.rb +14 -0
- data/photile.gemspec +17 -0
- data/test/test_photile.rb +9 -0
- metadata +75 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) photile 2012 Nitin Dhar
|
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,62 @@
|
|
1
|
+
# photile**
|
2
|
+
|
3
|
+
* * *
|
4
|
+
*A ruby gem/library to chop a photo into tiles, watermark them, etc*
|
5
|
+
* * *
|
6
|
+
|
7
|
+
`photile` can be used to power a web widget like [turnandzoom](https://github.com/nitindhar7/turnandzoom) or just about any simple image processing workflow. With `photile` you can run simple tasks like compression, watermarking and tiling images manually or in an automated fashion. These tasks can be combined to formulate a custom flow. For example, you can `compress an image` → `watermark it` → `break it up into tiles`.
|
8
|
+
|
9
|
+
One scenario where this is really useful is image processing for product images. Most product images are shot on white background, which means that there is a big opportunity to reduce image size and improve rendering speed on the web page. Here's what you can do with `photile`: `basic quality reduction` → `watermark your product images` → `break it up into tiles (certain tiles will be all white)` → `compress individual tiles`.
|
10
|
+
|
11
|
+
### Functions
|
12
|
+
|
13
|
+
* Quality manipulation
|
14
|
+
* Loss-less compression
|
15
|
+
* Watermarking
|
16
|
+
* Tiling
|
17
|
+
|
18
|
+
### Piping
|
19
|
+
|
20
|
+
The four main functions of `photile` can be used in all combinations possible because of their 'piping' properties (i.e., the Builder Pattern). Each function takes in an image and spits out an image or an array of images. When an array of images is returned any function thereafter is applied to all items in the array. When piping functions the order is relevant as the output of a function becomes the input of another. For example: `tile` → `watermark` (tiles images and then applies a watermark to the smaller, chopped images) is not the same as `watermark` → `tile` (watermarks an image and then creates tiles).
|
21
|
+
|
22
|
+
Here are the piping scenarios available
|
23
|
+
|
24
|
+
* `IMAGE` → `Quality Modifier` → `IMAGE`
|
25
|
+
* `IMAGE` → `Compressor` → `IMAGE`
|
26
|
+
* `IMAGE` + `WATERMARK IMAGE` → `Watermarker` → `IMAGE`
|
27
|
+
* `IMAGE` → `Tiler` → `[IMAGE...IMAGE]`
|
28
|
+
|
29
|
+
### Examples
|
30
|
+
|
31
|
+
```bash
|
32
|
+
# Basic Examples
|
33
|
+
$ photile -quality 80 image-in image-out
|
34
|
+
$ photile -compress image-in image-out
|
35
|
+
$ photile -watermark image-in image-watermark image-out
|
36
|
+
$ photile -tile WIDTHxHEIGHT image-in [image-out-0...image-out-n]
|
37
|
+
|
38
|
+
# Advanced Examples
|
39
|
+
|
40
|
+
# 1. Reduce quality and then loss less compression for 'image-in' to produce 'image-out'
|
41
|
+
$ photile -quality 80 -compress image-in image-out
|
42
|
+
|
43
|
+
# 2. Watermark 'image-in' with 'image-watermark' and then tile it with size 'WIDTHxHEIGHT' to produce '[image-out-0...image-out-n]'
|
44
|
+
$ photile -watermark -tile WIDTHxHEIGHT image-in image-watermark image-out
|
45
|
+
|
46
|
+
# 3. Reduce quality of 'image-in', then compress it and watermark it with 'image-watermark'. Finally, tile the watermarked image to produce '[image-out-0...image-out-n]'
|
47
|
+
$ photile -quality 80 -compress -watermark -tile WIDTHxHEIGHT image-in image-watermark [image-out-0...image-out-n]
|
48
|
+
```
|
49
|
+
|
50
|
+
### Dependencies
|
51
|
+
|
52
|
+
* **Imagemagick** - Follow the installation instructions [here](http://imagemagick.org) (on Linux you can install it using: `sudo apt-get install imagemagick imagemagick-common`).
|
53
|
+
* **Jpegtran** - Follow the installation instructions [here](http://jpegclub.org/jpegtran) (on Linux you can install it using: `sudo apt-get install libjpeg-turbo-progs`).
|
54
|
+
|
55
|
+
### More
|
56
|
+
|
57
|
+
Photile uses the amazing [Imagemagick](http://www.imagemagick.org/script/index.php) and [Jpegtran](http://jpegclub.org/jpegtran/) libraries. Imagemagick provides quality, watermarking and tiling properties. Jpegtran provides the loss-less compression. In other words, `photile` is just a layer on top of existing libraries to make certain image processing tasks dead simple. Additionally since `photile` is a gem it can be used directly in Rails to create dynamic workflows.
|
58
|
+
|
59
|
+
** `photile` is in a pre-release α state at the moment.
|
60
|
+
|
61
|
+
* * *
|
62
|
+
Copyright (c) 2012 Nitin Dhar. See [MIT-LICENSE](MIT-LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
Rake::TestTask.new do |t|
|
4
|
+
t.libs << 'test'
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Run unit tests"
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
desc "Build photile for testing"
|
11
|
+
task :build do
|
12
|
+
system 'gem build photile.gemspec && gem install ./*.gem --pre && rm *.gem'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Build docs"
|
16
|
+
task :docs do
|
17
|
+
`rdoc`
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Uninstalls the gem"
|
21
|
+
task :uninstall do
|
22
|
+
system 'gem uninstall photile'
|
23
|
+
end
|
data/bin/photile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'photile'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = []
|
7
|
+
|
8
|
+
optparse = OptionParser.new do|opts|
|
9
|
+
opts.banner = "Usage: photile [options] infile outfile"
|
10
|
+
|
11
|
+
opts.on('-q', '--quality VALUE', Integer, 'Modify image quality') do |value|
|
12
|
+
options << {:quality => value}
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on('-c', '--compress', 'Loss-less compress image') do
|
16
|
+
options << {:compress => true}
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on('-w', '--watermark FILE', String, 'Watermark with given file') do |file|
|
20
|
+
options << {:watermark => file}
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-t', '--tile WIDTHxHEIGHT', Regexp.new(/\d+x\d+/), 'Tile to the given dimensions') do |dimensions|
|
24
|
+
dim = dimensions.split('x')
|
25
|
+
options << {:tile => {:width => dim.first.to_i, :height => dim.last.to_i}}
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-h', '--help', 'Display options help') do
|
29
|
+
puts opts
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
optparse.parse!
|
36
|
+
|
37
|
+
if options.empty?
|
38
|
+
puts optparse
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
puts options
|
43
|
+
rescue OptionParser::InvalidArgument => ia
|
44
|
+
puts ia
|
45
|
+
exit
|
46
|
+
end
|
data/lib/photile.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
=begin
|
2
|
+
namespace :image do
|
3
|
+
|
4
|
+
desc "Displays the size of an image"
|
5
|
+
task :size do
|
6
|
+
size = `identify tmp/original.jpeg`.split(" ")[6]
|
7
|
+
puts "Image size: #{size}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Changes the quality of an image"
|
11
|
+
task :quality do
|
12
|
+
`convert tmp/original.jpeg -quality 70 tmp/quality70.jpeg`
|
13
|
+
size = `identify tmp/quality70.jpeg`.split(" ")[6]
|
14
|
+
puts "Image size: #{size}"
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Changes the quality of an image with 2 compressions"
|
18
|
+
task :quality_advanced do
|
19
|
+
`convert tmp/original.jpeg -quality 70 tmp/quality70.jpeg`
|
20
|
+
`jpegtran -copy none -optimize -perfect -outfile tmp/quality70.jpeg tmp/quality70.jpeg`
|
21
|
+
size = `identify tmp/quality70.jpeg`.split(" ")[6]
|
22
|
+
puts "Image size: #{size}"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Applies a watermark to an image"
|
26
|
+
task :watermark do
|
27
|
+
`composite -gravity center tmp/watermark.png tmp/original.jpeg tmp/watermarked.jpeg`
|
28
|
+
size = `identify tmp/watermarked.jpeg`.split(" ")[6]
|
29
|
+
puts "Watermarked image. Image size: #{size}"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Tiles an image by chopping it up into fragments"
|
33
|
+
task :tile do
|
34
|
+
`convert tmp/original.jpeg -crop 300x300 +repage +adjoin tmp/tile_%02d.jpeg`
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Cleans up temporary files generated"
|
38
|
+
task :clean do
|
39
|
+
`rm tmp/quality70.jpeg 2>&1`
|
40
|
+
`rm tmp/watermarked.jpeg 2>&1`
|
41
|
+
`rm tmp/tile_*.jpeg 2>&1`
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
=end
|
46
|
+
# The main Photile driver
|
47
|
+
class Photile
|
48
|
+
|
49
|
+
# Say hi to the world!
|
50
|
+
#
|
51
|
+
# Example:
|
52
|
+
# >> Photile.hi("spanish")
|
53
|
+
# => hola mundo
|
54
|
+
#
|
55
|
+
# Arguments:
|
56
|
+
# language: (String)
|
57
|
+
def self.hi(language = "english")
|
58
|
+
translator = Translator.new(language)
|
59
|
+
puts translator.hi
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
require 'photile/translator'
|
data/photile.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'photile'
|
3
|
+
s.version = '0.1.0.pre'
|
4
|
+
s.date = '2012-11-02'
|
5
|
+
s.summary = 'A ruby gem to chop a photo into tiles, watermark them, etc.'
|
6
|
+
s.description = 'Photile is just a layer on top of Imagemagick and Jpegtran to make certain image processing tasks dead simple.'
|
7
|
+
s.author = 'Nitin Dhar'
|
8
|
+
s.email = 'nitindhar7@yahoo.com'
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.executables = ['photile']
|
11
|
+
s.bindir = 'bin'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.homepage = 'https://github.com/nitindhar7/photile'
|
14
|
+
s.add_development_dependency 'rake', ['>= 0.9.2']
|
15
|
+
s.required_ruby_version = '>= 1.8.7'
|
16
|
+
s.requirements << 'imagemagick' << 'imagemagick-common' << 'libjpeg-turbo-progs'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: photile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nitin Dhar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.2
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.2
|
30
|
+
description: Photile is just a layer on top of Imagemagick and Jpegtran to make certain
|
31
|
+
image processing tasks dead simple.
|
32
|
+
email: nitindhar7@yahoo.com
|
33
|
+
executables:
|
34
|
+
- photile
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- MIT-LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/photile
|
43
|
+
- lib/photile.rb
|
44
|
+
- lib/photile/translator.rb
|
45
|
+
- photile.gemspec
|
46
|
+
- test/test_photile.rb
|
47
|
+
homepage: https://github.com/nitindhar7/photile
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.8.7
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>'
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.3.1
|
66
|
+
requirements:
|
67
|
+
- imagemagick
|
68
|
+
- imagemagick-common
|
69
|
+
- libjpeg-turbo-progs
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.24
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: A ruby gem to chop a photo into tiles, watermark them, etc.
|
75
|
+
test_files: []
|