rendaku 1.0.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.
- checksums.yaml +7 -0
- data/.travis.yml +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +20 -0
- data/README.md +11 -0
- data/Rakefile +8 -0
- data/lib/rendaku/version.rb +3 -0
- data/lib/rendaku.rb +124 -0
- data/rendaku.gemspec +20 -0
- data/test/test_images/ankh.png +0 -0
- data/test/test_rendaku.rb +40 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e331152fd22cbf0bfdc63cf645c14de30e021941
|
4
|
+
data.tar.gz: a8ef2e1b61a5f476b86024edb6513647680a94d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e01b15e3361576f1942370f685f1d22d5ebfe80edf96219172d2875f39302cfb6ed52ca477e2141dcedc6e21d857d9dd700f42e08bcc7bcd31ea673a514e6e49
|
7
|
+
data.tar.gz: 715eb7e49535a00fd88610e17b39964cd8adba6f76df51be3ff8e97be3014924d1edd5f4434c56c461e905b35f1a729212590327b29c3a8b28d710d0bfae1dd0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rendaku (0.0.0)
|
5
|
+
rmagick (~> 2.13)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
minitest (5.5.1)
|
11
|
+
rake (10.4.2)
|
12
|
+
rmagick (2.13.4)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
minitest
|
19
|
+
rake
|
20
|
+
rendaku!
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Rendaku [](https://travis-ci.org/travis-anderson/rendaku)
|
2
|
+
|
3
|
+
Rendaku is a ruby gem which accepts book dimensions and a simple image file for
|
4
|
+
generating book art page-folding instructions.
|
5
|
+
|
6
|
+

|
7
|
+
|
8
|
+
Inspired by the work at https://github.com/Moini/BookArtGenerator
|
9
|
+
|
10
|
+
|
11
|
+
|
data/Rakefile
ADDED
data/lib/rendaku.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
module Rendaku
|
2
|
+
require 'rmagick'
|
3
|
+
include Magick
|
4
|
+
|
5
|
+
class Book
|
6
|
+
attr_accessor :first_page, :last_page, :height
|
7
|
+
|
8
|
+
def initialize fp, lp, h
|
9
|
+
@first_page = fp
|
10
|
+
@last_page = lp
|
11
|
+
@height = h
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Pattern
|
16
|
+
attr_accessor :book, :image, :template
|
17
|
+
|
18
|
+
def initialize b, i
|
19
|
+
@book = b
|
20
|
+
@image = i
|
21
|
+
@template = fold_template prepare_pattern
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def fold_template pattern
|
27
|
+
template = []
|
28
|
+
pattern.each_with_index do |contents, col|
|
29
|
+
top_corner = contents[0][:start]
|
30
|
+
bottom_corner = contents[0][:end]
|
31
|
+
page = (col*2) + @book.first_page
|
32
|
+
|
33
|
+
template << { page: page, top: top_corner, bottom: bottom_corner }
|
34
|
+
end
|
35
|
+
|
36
|
+
template
|
37
|
+
end
|
38
|
+
|
39
|
+
def prepare_pattern
|
40
|
+
pages = (@book.last_page - @book.first_page)/2 + 1
|
41
|
+
height = @book.height * 100
|
42
|
+
image = squish_image pages, height, @image
|
43
|
+
white = Rendaku::Pixel.from_color 'white'
|
44
|
+
pattern = []
|
45
|
+
|
46
|
+
pages.times do |x|
|
47
|
+
pixel_above = nil
|
48
|
+
changes = false
|
49
|
+
color_bands = -1
|
50
|
+
pattern[x] = []
|
51
|
+
|
52
|
+
height.times do |y|
|
53
|
+
pixel = image.pixel_color(x, y)
|
54
|
+
if pixel_above.nil? && pixel != white
|
55
|
+
pixel_above = pixel
|
56
|
+
color_bands += 1
|
57
|
+
pattern[x][color_bands] = { start: 0 }
|
58
|
+
changes = true
|
59
|
+
elsif pixel != white && y == height-1
|
60
|
+
pattern[x][color_bands][:end] = (y+1).fdiv(100)
|
61
|
+
changes = true
|
62
|
+
elsif pixel_above.nil? || pixel_above == pixel
|
63
|
+
pixel_above = pixel
|
64
|
+
next
|
65
|
+
elsif pixel_above == white && pixel != white
|
66
|
+
pixel_above = pixel
|
67
|
+
color_bands += 1
|
68
|
+
pattern[x][color_bands] = { start: y.fdiv(100) }
|
69
|
+
changes = true
|
70
|
+
elsif pixel_above != white && pixel == white
|
71
|
+
pixel_above = pixel
|
72
|
+
pattern[x][color_bands][:end] = (y+1).fdiv(100)
|
73
|
+
changes = true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
pattern[x] = "nofolds" unless changes
|
77
|
+
end
|
78
|
+
|
79
|
+
create_final pattern
|
80
|
+
end
|
81
|
+
|
82
|
+
def squish_image pages, height, image
|
83
|
+
img = image.resize! pages, height
|
84
|
+
img.threshold Rendaku::QuantumRange*0.5
|
85
|
+
end
|
86
|
+
|
87
|
+
def too_many_holes? pattern
|
88
|
+
empty = 0
|
89
|
+
empty_allowed = 0
|
90
|
+
|
91
|
+
empty_allowed += 1 if pattern[0] == "nofolds"
|
92
|
+
empty_allowed += 1 if pattern.last == "nofolds"
|
93
|
+
|
94
|
+
pattern.each_with_index do |p, i|
|
95
|
+
if p == "nofolds"
|
96
|
+
if i == 0
|
97
|
+
empty += 1
|
98
|
+
elsif pattern[i-1] != "nofolds"
|
99
|
+
empty += 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
empty > empty_allowed
|
105
|
+
end
|
106
|
+
|
107
|
+
def create_final pattern
|
108
|
+
final_pattern = []
|
109
|
+
|
110
|
+
pattern.each_with_index do |bands,col|
|
111
|
+
if bands.length == 1
|
112
|
+
final_pattern[col] = bands unless bands == "nofolds"
|
113
|
+
next
|
114
|
+
elsif bands.length > 6
|
115
|
+
raise "Too much detail"
|
116
|
+
else
|
117
|
+
final_pattern[col] = [bands[col%bands.length]]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
final_pattern
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/rendaku.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'rendaku/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'rendaku'
|
7
|
+
s.version = Rendaku::VERSION
|
8
|
+
s.authors = ['Travis Anderson']
|
9
|
+
s.email = 'dev-anderson@augustdecember.com'
|
10
|
+
s.description = 'Tool for creating book-folding template instructions. Inspired by https://github.com/Moini/BookArtGenerator'
|
11
|
+
s.summary = 'Tool for creating book-folding template instructions.'
|
12
|
+
s.homepage = 'https://github.com/travis-anderson/rendaku'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_dependency 'rmagick', '~> 2.13'
|
20
|
+
end
|
Binary file
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require './lib/rendaku'
|
3
|
+
|
4
|
+
class TestRendaku < Minitest::Test
|
5
|
+
include Rendaku
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@image = Image::read(File.dirname(__FILE__)+'/test_images/ankh.png')[0]
|
9
|
+
@book = Book.new 2, 300, 18
|
10
|
+
@pattern = Pattern.new @book, @image
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_book_has_properties
|
14
|
+
assert_equal @book.first_page, 2
|
15
|
+
assert_equal @book.last_page, 300
|
16
|
+
assert_equal @book.height, 18
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_image_has_properties
|
20
|
+
assert_includes @image.filename, 'ankh.png'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_pattern_has_properties
|
24
|
+
assert_equal @pattern.image, @image
|
25
|
+
assert_equal @pattern.book, @book
|
26
|
+
refute_empty @pattern.template
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_template_has_properties
|
30
|
+
assert_includes @pattern.template[0], :page
|
31
|
+
assert_includes @pattern.template[0], :top
|
32
|
+
assert_includes @pattern.template[0], :bottom
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_template_has_correct_values
|
36
|
+
assert_equal @pattern.template[0][:page], 2
|
37
|
+
assert_equal @pattern.template[0][:top], 6.04
|
38
|
+
assert_equal @pattern.template[0][:bottom], 6.08
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rendaku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Anderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.13'
|
27
|
+
description: Tool for creating book-folding template instructions. Inspired by https://github.com/Moini/BookArtGenerator
|
28
|
+
email: dev-anderson@augustdecember.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".travis.yml"
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/rendaku.rb
|
39
|
+
- lib/rendaku/version.rb
|
40
|
+
- rendaku.gemspec
|
41
|
+
- test/test_images/ankh.png
|
42
|
+
- test/test_rendaku.rb
|
43
|
+
homepage: https://github.com/travis-anderson/rendaku
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.4.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Tool for creating book-folding template instructions.
|
67
|
+
test_files:
|
68
|
+
- test/test_images/ankh.png
|
69
|
+
- test/test_rendaku.rb
|