doodler 1.1.0
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 +18 -0
- data/.rspec +1 -0
- data/.rvmrc +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +11 -0
- data/doodler.gemspec +21 -0
- data/image/baseline/baseline_1.png +0 -0
- data/image/baseline/baseline_2.png +0 -0
- data/image/baseline/baseline_3.png +0 -0
- data/image/baseline/baseline_4.png +0 -0
- data/image/baseline/baseline_5.png +0 -0
- data/image/baseline/baseline_6.png +0 -0
- data/lib/doodler/notification.rb +11 -0
- data/lib/doodler/runner.rb +8 -0
- data/lib/doodler/strategy.rb +61 -0
- data/lib/doodler/version.rb +3 -0
- data/lib/doodler.rb +17 -0
- data/spec/doodler/runner_spec.rb +29 -0
- data/spec/spec_helper.rb +7 -0
- metadata +84 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Marshall Shen
|
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,39 @@
|
|
1
|
+
# Doodler
|
2
|
+
Doodler is a Ruby Gem for Image Processing, it tries to redraw pictures
|
3
|
+
in human-like fashion
|
4
|
+
|
5
|
+
## Doodler 1.1 updates
|
6
|
+
|
7
|
+
- Speed up image recreating
|
8
|
+
- Improve test coverage
|
9
|
+
- Diversify image processing methods (bubblize, cubify, textify)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'doodler'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install doodler
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
```ruby
|
27
|
+
IMAGE_PATH="image/baseline/baseline_1.png" rake draw
|
28
|
+
|
29
|
+
> Doodler starts drawing! ...
|
30
|
+
> Doodle completes drawing! Image is saved in image/render/output.png
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "chunky_png"
|
3
|
+
require File.join(File.dirname(__FILE__), 'lib', 'doodler')
|
4
|
+
|
5
|
+
task :draw do
|
6
|
+
image_path = ENV["IMAGE_PATH"]
|
7
|
+
strategy = ENV["STRATEGY"]
|
8
|
+
|
9
|
+
image = ChunkyPNG::Image.from_file(image_path)
|
10
|
+
Doodler.draw(image, strategy)
|
11
|
+
end
|
data/doodler.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 'doodler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "doodler"
|
8
|
+
gem.version = Doodler::VERSION
|
9
|
+
gem.authors = ["Marshall Shen"]
|
10
|
+
gem.email = ["mshen@groupon.com"]
|
11
|
+
gem.description = "Ruby image processing package using ChunkyPNG"
|
12
|
+
gem.summary = "Ruby image processing package using ChunkyPNG"
|
13
|
+
gem.homepage = "https://github.com/marshallshen/doodler"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
gem.add_dependency "chunky_png"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Doodler
|
2
|
+
class Strategy
|
3
|
+
include ::ChunkyPNG::Color
|
4
|
+
include Doodler::Notification
|
5
|
+
|
6
|
+
attr_accessor :image
|
7
|
+
|
8
|
+
def initialize(image)
|
9
|
+
@image = image
|
10
|
+
end
|
11
|
+
|
12
|
+
def bubblize
|
13
|
+
notify_start
|
14
|
+
|
15
|
+
50000.times do
|
16
|
+
centre = [rand(width), rand(height)] ; radius = rand(5)
|
17
|
+
color = ChunkyPNG::Color(image[centre[0], centre[1]])
|
18
|
+
|
19
|
+
left = [0, centre[0] - radius].max
|
20
|
+
right = [centre[0] + radius, (width-1)].min
|
21
|
+
up = [centre[1] + radius, (height-1)].min
|
22
|
+
down = [0, centre[1] - radius].max
|
23
|
+
|
24
|
+
(left..right).to_a.each do |x|
|
25
|
+
(down..up).to_a.each do |y|
|
26
|
+
image[x,y] = color if distance_from_centre(centre, x, y) <= radius
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
render
|
33
|
+
notify_complete
|
34
|
+
end
|
35
|
+
|
36
|
+
def cubify
|
37
|
+
# another method
|
38
|
+
end
|
39
|
+
|
40
|
+
def textify
|
41
|
+
# another method
|
42
|
+
end
|
43
|
+
|
44
|
+
def render
|
45
|
+
image.save("image/render/output.png")
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def height
|
50
|
+
image.height
|
51
|
+
end
|
52
|
+
|
53
|
+
def width
|
54
|
+
image.width
|
55
|
+
end
|
56
|
+
|
57
|
+
def distance_from_centre(centre, x, y)
|
58
|
+
Math.sqrt(((x-centre[0])**2 + (y-centre[1])**2))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/doodler.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/doodler/version')
|
2
|
+
require File.join(File.dirname(__FILE__), '/doodler/runner')
|
3
|
+
require File.join(File.dirname(__FILE__), '/doodler/notification')
|
4
|
+
require File.join(File.dirname(__FILE__), '/doodler/strategy')
|
5
|
+
require 'chunky_png'
|
6
|
+
|
7
|
+
module Doodler
|
8
|
+
NoImageFound = "Hmm, I didn't see any picture here.."
|
9
|
+
ImageSizeInconsistency = "Oops, the two pictures have different sizes.."
|
10
|
+
FailToImprove = "Hm, my doodling doesn't look like the picture you provided at all! Let me try again.."
|
11
|
+
Exit = "I am done drawing. Go check out how I do!"
|
12
|
+
|
13
|
+
def self.draw(image, strategy)
|
14
|
+
raise Doodler::NoImageFound unless image
|
15
|
+
Doodler::Runner.draw!(image, strategy)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Doodler::Runner do
|
4
|
+
let(:image) {mock("test image", :width => 100, :height => 100)}
|
5
|
+
let(:strategy) { mock("strategy") }
|
6
|
+
|
7
|
+
describe "#draw" do
|
8
|
+
context "#strategy" do
|
9
|
+
it "starts drawing with a default strategy" do
|
10
|
+
Doodler::Strategy.should_receive(:new).with(image).and_return(strategy)
|
11
|
+
strategy.should_receive(:bubblize)
|
12
|
+
Doodler::Runner.draw!(image, nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "starts drawing with a choosen strategy if strategy is passed in param" do
|
16
|
+
Doodler::Strategy.should_receive(:new).with(image).and_return(strategy)
|
17
|
+
strategy.should_receive(:textify)
|
18
|
+
Doodler::Runner.draw!(image, :textify)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#render" do
|
24
|
+
it "saves image to the right directory" do
|
25
|
+
image.should_receive(:save).with("image/render/output.png")
|
26
|
+
Doodler::Strategy.new(image).render
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doodler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marshall Shen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chunky_png
|
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: Ruby image processing package using ChunkyPNG
|
31
|
+
email:
|
32
|
+
- mshen@groupon.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- .rvmrc
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- doodler.gemspec
|
45
|
+
- image/baseline/baseline_1.png
|
46
|
+
- image/baseline/baseline_2.png
|
47
|
+
- image/baseline/baseline_3.png
|
48
|
+
- image/baseline/baseline_4.png
|
49
|
+
- image/baseline/baseline_5.png
|
50
|
+
- image/baseline/baseline_6.png
|
51
|
+
- lib/doodler.rb
|
52
|
+
- lib/doodler/notification.rb
|
53
|
+
- lib/doodler/runner.rb
|
54
|
+
- lib/doodler/strategy.rb
|
55
|
+
- lib/doodler/version.rb
|
56
|
+
- spec/doodler/runner_spec.rb
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
homepage: https://github.com/marshallshen/doodler
|
59
|
+
licenses: []
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.25
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Ruby image processing package using ChunkyPNG
|
82
|
+
test_files:
|
83
|
+
- spec/doodler/runner_spec.rb
|
84
|
+
- spec/spec_helper.rb
|