termdots 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a3eeaa9e451c7cd463b8169a00e56c6a44888b01
4
+ data.tar.gz: eee2843c79db803fd7f5e407199351c298b1f421
5
+ SHA512:
6
+ metadata.gz: 64e6741a50b7e9da049c439789675c9add7a1879a257ab39a4b22d6665bf8902e7a88123f7e4d1275afd20297a9532ba9a677e08c754d1c8be0774f4fa460308
7
+ data.tar.gz: 4666ae0fdcf6754e686f0834294f4c139a1479bf7ffd40b24c82aaedfdb294077a04a52d74333fe247e761facdcbfd9b234043f7f1feb675a949f64651e7ab45
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at na.kendroid@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in termdots.gemspec
4
+ gemspec
5
+ gem "rmagick"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 kenta nakagawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # Termdots
2
+
3
+ **Converts the image to Dot picture**
4
+ ![apple](https://i.gyazo.com/6be17ab221d6684c38c485138b4c58a8.png)
5
+
6
+ ## Requirement
7
+
8
+ [rmagick](http://rmagick.rubyforge.org/)
9
+
10
+ ## Install
11
+
12
+ Or install it yourself as:
13
+
14
+ $ gem install termdots
15
+
16
+ ## Usage
17
+
18
+ % termdots
19
+ Please enter a image path
20
+ /Users/username/Pictures/sample.jpg
21
+
22
+ ## License
23
+
24
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "termdots"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'termdots'
4
+
5
+ puts Termdots.main
@@ -0,0 +1,166 @@
1
+ require "termdots/version"
2
+ require "RMagick"
3
+
4
+ include Magick
5
+
6
+ FILENAME = ARGV[0]
7
+ ELEM_STR = " "
8
+ COLOR_MODE = 2 # 1: 16colors, 2: 256colors
9
+
10
+ module Termdots
11
+ def output_image(file_name)
12
+ cg = ColorGenerator.new(COLOR_MODE)
13
+ cg.set_transparent_color(0, 0, 0)
14
+
15
+ img = ImageList.new(file_name)
16
+ img = img.resize_to_fit(32, 32)
17
+ for y in 0...img.rows
18
+ for x in 0...img.columns
19
+ src = img.pixel_color(x, y)
20
+ r = src.red / 256
21
+ g = src.green / 256
22
+ b = src.blue / 256
23
+
24
+ print cg.convert(r, g, b) + get_elem_str + cg.clear_color
25
+ end
26
+ puts ""
27
+ end
28
+ end
29
+
30
+ def get_elem_str
31
+ return ELEM_STR
32
+ end
33
+
34
+ def main
35
+ # file_name = FILENAME.to_s
36
+ puts 'Please enter a image path'
37
+ file_name = gets.chomp.to_s
38
+ if !File.exists?(file_name)
39
+ puts "image file not found."
40
+ exit
41
+ end
42
+ output_image(file_name)
43
+ end
44
+
45
+
46
+ # =========================
47
+ # Color generator class
48
+ # =========================
49
+ class ColorGenerator
50
+
51
+ # color mode
52
+ COLOR_MODE_16 = 1
53
+ COLOR_MODE_256 = 2
54
+
55
+ # color => [r, g, b]
56
+ CT_RGB = {
57
+ :black => [0, 0, 0],
58
+ :red => [205, 0, 0],
59
+ :green => [0, 205, 0],
60
+ :yellow => [205, 205, 0],
61
+ :blue => [0, 0, 238],
62
+ :magenta => [205, 0, 205],
63
+ :cyan => [0, 205, 205],
64
+ :gray => [229, 229, 229],
65
+ :darkgray => [127, 127, 127],
66
+ :l_red => [255, 0, 0],
67
+ :l_green => [0, 255, 0],
68
+ :l_yellow => [255, 255, 0],
69
+ :l_blue => [92, 92, 255],
70
+ :l_magenta => [255, 0, 255],
71
+ :l_cyan => [0, 255, 255],
72
+ :white => [255, 255, 255]
73
+ }
74
+
75
+ # color => ANSI escape code
76
+ CT_ANSI = {
77
+ :black => "\033[40m",
78
+ :red => "\033[41m",
79
+ :green => "\033[42m",
80
+ :yellow => "\033[43m",
81
+ :blue => "\033[44m",
82
+ :magenta => "\033[45m",
83
+ :cyan => "\033[46m",
84
+ :gray => "\033[47m",
85
+ :darkgray => "\033[100m",
86
+ :l_red => "\033[101m",
87
+ :l_green => "\033[102m",
88
+ :l_yellow => "\033[103m",
89
+ :l_blue => "\033[104m",
90
+ :l_magenta => "\033[105m",
91
+ :l_cyan => "\033[106m",
92
+ :white => "\033[107m"
93
+ }
94
+
95
+
96
+ def initialize(mode)
97
+ @mode = mode
98
+ @tr = -1
99
+ @tg = -1
100
+ @tb = -1
101
+ end
102
+
103
+ def set_transparent_color(r, g, b)
104
+ @tr = r
105
+ @tg = g
106
+ @tb = b
107
+ end
108
+
109
+ def transparent_color?(r, g, b)
110
+ return r == @tr && g == @tg && b == @tb
111
+ end
112
+
113
+ # r,g,b = (0...255)
114
+ def convert(r, g, b)
115
+ if @mode == COLOR_MODE_16
116
+ return convert16(r, g, b)
117
+ elsif @mode == COLOR_MODE_256
118
+ return convert256(r, g, b)
119
+ else
120
+ return ""
121
+ end
122
+ end
123
+
124
+ def convert16(r, g, b)
125
+ if transparent_color?(r, g, b)
126
+ return ""
127
+ end
128
+
129
+ diff_min = 255 * 3
130
+ ret = CT_ANSI[:black]
131
+ CT_RGB.each do |color, rgb|
132
+ diff = (r - rgb[0]).abs + (g - rgb[1]).abs + (b - rgb[2]).abs
133
+ if diff < diff_min
134
+ ret = CT_ANSI[color]
135
+ diff_min = diff
136
+ end
137
+ end
138
+
139
+ return ret
140
+ end
141
+
142
+ def convert256(r, g, b)
143
+ if transparent_color?(r, g, b)
144
+ return ""
145
+ end
146
+
147
+ code = (r * 5 / 255 * 36) + (g * 5 / 255 * 6) + (b * 5 / 255) + 16
148
+ ret = "\033[48;5;" + code.to_s + "m"
149
+
150
+ return ret
151
+ end
152
+
153
+ def clear_color
154
+ return "\033[0m"
155
+ end
156
+
157
+ def test
158
+ puts "\033[40m \033[41m \033[42m \033[43m \033[44m \033[45m \033[46m \033[47m \033[0m"
159
+ puts "\033[100m \033[101m \033[102m \033[103m \033[104m \033[105m \033[106m \033[107m \033[0m"
160
+ end
161
+ end
162
+
163
+ # main
164
+ module_function :output_image, :get_elem_str, :main
165
+
166
+ end
@@ -0,0 +1,3 @@
1
+ module Termdots
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'termdots/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "termdots"
8
+ spec.version = Termdots::VERSION
9
+ spec.authors = ["kenta nakagawa"]
10
+ spec.email = ["na.kendroid@gmail.com"]
11
+
12
+ spec.summary = %q{taeminal Dot}
13
+ spec.description = %q{convert from image to Dot}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ # spec.bindir = "exe"
27
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.bindir = "bin"
29
+ spec.executables = ['termdots']
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency 'rmagick'
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.11"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: termdots
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kenta nakagawa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-15 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
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: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: convert from image to Dot
70
+ email:
71
+ - na.kendroid@gmail.com
72
+ executables:
73
+ - termdots
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - bin/termdots
88
+ - lib/termdots.rb
89
+ - lib/termdots/version.rb
90
+ - termdots.gemspec
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: taeminal Dot
115
+ test_files: []