rmagick-tti_converter 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.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +27 -0
- data/lib/rmagick/tti_converter.rb +64 -0
- data/lib/rmagick/tti_converter/version.rb +5 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e452b48be147ad3741463f34d920e258a76e5f90
|
4
|
+
data.tar.gz: 0d4369e91dfc2a57a1c9cfd2249a36e623d4f3eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a6e024bba3d89f385274a28e84d20ba68c0e59bb1110832a93aa39c8d3010898df09a59e5e7d6fbb1a30fb5d07fc860da88376d914928b43e52744246d0623d
|
7
|
+
data.tar.gz: 7193eb0dbc7937dba94e251c9ad934577736f0ec183058dee72e9d2385804d9d0dc0c1ccd2366d3b9aaea4ed6a23632cd692cbbf9e0d4e5a8ff2bb5b8f429b63
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
LICENSE
|
2
|
+
|
3
|
+
The MIT License
|
4
|
+
|
5
|
+
Copyright (c) 2015 Alyautdinov Rushan(rushan_oline@mail.ru).
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
9
|
+
in the Software without restriction, including without limitation the rights
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
12
|
+
furnished to do so, subject to the following conditions:
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## Text to image Converter
|
2
|
+
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
require 'rmagick/tti_converter'
|
8
|
+
|
9
|
+
text_wrapper = Magick::TTIConverter.new("./imgs_with_txt/")
|
10
|
+
|
11
|
+
source_text =<<-SomeTextD
|
12
|
+
The arguments are pairs of points. At least 4 pairs must be specified. Each point xn, yn on the curve is associated with a control point cxn, cyn. The first point, x1, y1, is the starting point. The last point, xn, yn, is the ending point. Other point/control point pairs specify intermediate points on a polybezier curve.
|
13
|
+
SomeTextD
|
14
|
+
|
15
|
+
text_wrapper.make_image(source_text, file_name: "func_descr.jpg")
|
16
|
+
```
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
1. Fork it ( https://github.com/sinventor/rmagick-tti_converter/fork )
|
20
|
+
2. Create your feature branch (`git checkout -b some-feature`)
|
21
|
+
3. Commit your feature branch (`git commit -am 'Add some feature'`)
|
22
|
+
4. Push to the branch (`git push origin some-feature`)
|
23
|
+
5. Create a new Pull Request
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
require 'rmagick/tti_converter/version'
|
3
|
+
|
4
|
+
module Magick
|
5
|
+
class TTIConverter
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
unless File.exists?(@path)
|
9
|
+
@path = "./tmp/"
|
10
|
+
Dir.mkdir("./tmp") unless File.exists?("./tmp")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def make_image(text, options = {})
|
15
|
+
file_name = options[:file_name] || "image.jpg"
|
16
|
+
image = Magick::Image.new(50,50)
|
17
|
+
draw = Magick::Draw.new
|
18
|
+
optimal_width = 80
|
19
|
+
start = 0
|
20
|
+
finish = optimal_width
|
21
|
+
positions = []
|
22
|
+
edited_text = text.dup
|
23
|
+
|
24
|
+
while positions.length < text.length / optimal_width
|
25
|
+
space_index = get_index_nearest_space(text, {
|
26
|
+
start: start,
|
27
|
+
finish: finish
|
28
|
+
})
|
29
|
+
if space_index != -1
|
30
|
+
positions << space_index
|
31
|
+
start = space_index + 1
|
32
|
+
finish = space_index + optimal_width
|
33
|
+
else
|
34
|
+
positions << finish
|
35
|
+
start = start + optimal_width + 1
|
36
|
+
finish = start + optimal_width
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
positions.each { |pos| edited_text[pos] = "\n" }
|
41
|
+
current_metrics = draw.get_multiline_type_metrics(image, edited_text)
|
42
|
+
width = current_metrics.width
|
43
|
+
height = current_metrics.height
|
44
|
+
image = Magick::Image.new(width + 25, height + 35)
|
45
|
+
draw.text(15, 25, edited_text)
|
46
|
+
draw.draw(image)
|
47
|
+
image.write(@path + file_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def get_index_nearest_space(text, options = {})
|
53
|
+
start = options[:start] || 0
|
54
|
+
finish = options[:finish] || (start + 80)
|
55
|
+
current_pos = finish
|
56
|
+
|
57
|
+
loop do
|
58
|
+
return -1 if current_pos - start < 0
|
59
|
+
return current_pos if text[current_pos] == " "
|
60
|
+
current_pos -= 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rmagick-tti_converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rushan Alyautdinov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-22 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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description: Text manipulator to make image with text content
|
70
|
+
email: rushan_oline@mail.ru
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- LICENSE
|
76
|
+
- README.md
|
77
|
+
- lib/rmagick/tti_converter.rb
|
78
|
+
- lib/rmagick/tti_converter/version.rb
|
79
|
+
homepage: https://github.com/sinventor/rmagick-tti_converter
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Text to image converter
|
103
|
+
test_files: []
|