cmagick 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aa905506e3bd9f9fb3735a818f0feec0e8190bc9e1d1c7cf8b43eb4c8a27b701
4
+ data.tar.gz: 9733dfce07d31775af92007878c7983fb52d10ddf5446c8749a3624434a636f1
5
+ SHA512:
6
+ metadata.gz: 9af0451e5d80eafc329546e65d03246ded80e684ac57c18c037ac28837acb18bc0bd07dd29ad5fff5af832fefc0e4901e4c19281180d22cd8e019e59ebf17dfb
7
+ data.tar.gz: 82f673af0969f80783fb53f5ff21cb174cb072b88176ea11e6f1f30d19db37eafc502d544e560dfd1c36a61cbdd94c4fa9c3ed409a8900428d4cd0fc89336e62
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ vendor
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.4
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tsukamoto@fusic.co.jp. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in cmagick.gemspec
6
+ gemspec
7
+
8
+ gem 'pry'
9
+ gem 'rake', '~> 12.0'
10
+ gem 'rmagick'
11
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cmagick (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (1.0.0)
12
+ pry (0.13.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (12.3.3)
16
+ rmagick (4.1.2)
17
+ rspec (3.9.0)
18
+ rspec-core (~> 3.9.0)
19
+ rspec-expectations (~> 3.9.0)
20
+ rspec-mocks (~> 3.9.0)
21
+ rspec-core (3.9.1)
22
+ rspec-support (~> 3.9.1)
23
+ rspec-expectations (3.9.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-mocks (3.9.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.9.0)
29
+ rspec-support (3.9.2)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ cmagick!
36
+ pry
37
+ rake (~> 12.0)
38
+ rmagick
39
+ rspec (~> 3.0)
40
+
41
+ BUNDLED WITH
42
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # CMagick
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cmagick`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ It is a gem that can display images on the console.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cmagick'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cmagick
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ cmagick = CMagick::LoadImage.new('/path/to/img.jpg')
27
+ cmagick.show
28
+ ```
29
+
30
+ if img is big size
31
+
32
+ ```
33
+ cmagick.resize(0.1).show
34
+ ```
35
+
36
+ ## Example
37
+
38
+ Left: original
39
+
40
+ Right: convert ansi code
41
+
42
+ ![バーくん](./resources/bar.png)
43
+
44
+ source: https://twitter.com/raibarori/status/1028576227571847168/photo/1
45
+
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/TsuMakoto/cmagick. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/TsuMakoto/cmagick/blob/master/CODE_OF_CONDUCT.md).
56
+
57
+
58
+ ## Code of Conduct
59
+
60
+ Everyone interacting in the CMagick project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/TsuMakoto/cmagick/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cmagick"
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 "pry"
14
+ Pry.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/cmagick.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/cmagick/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'cmagick'
7
+ spec.version = CMagick::VERSION
8
+ spec.authors = ['TsuMakoto']
9
+ spec.email = ['tsukamoto@fusic.co.jp']
10
+
11
+ spec.summary = 'A tool to display images on the console'
12
+ spec.description = <<~EOF
13
+ To display the image programmatically,
14
+ - you can start the web application,
15
+ - save the image and display it again with the tool,
16
+ - or display it with the jupyter notebook.
17
+ However, for me, that one step is very troublesome.
18
+ So I created a tool that allows you to view the image as it is at the console at runtime.
19
+ EOF
20
+
21
+ spec.homepage = 'https://github.com/TsuMakoto/cmagick/blob/master/README.md'
22
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CMagick
4
+ # c = ColorContol.new
5
+
6
+ # r = 'ff'.hex
7
+ # g = 'e7'.hex
8
+ # b = 'f4'.hex
9
+ # c.call(r: r, g: g, b: b)
10
+ # => 224
11
+ #
12
+ # r = 'ff'.hex
13
+ # g = 'ff'.hex
14
+ # b = 'ff'.hex
15
+ # c.call(r: r, g: g, b: b)
16
+ # => 231
17
+ #
18
+ # r = '00'.hex
19
+ # g = '00'.hex
20
+ # b = '00'.hex
21
+ # c.call(r: r, g: g, b: b)
22
+ # => 16
23
+ # rubocop:disable Naming/UncommunicativeMethodParamName
24
+ class RGBToANSI
25
+ class << self
26
+ def call(r, g, b)
27
+ ansi(r, g, b)
28
+ end
29
+
30
+ private
31
+
32
+ def ansi(r, g, b)
33
+ (r * 5 / 255 * 36) + (g * 5 / 255 * 6) + (b * 5 / 255) + 16
34
+ end
35
+ end
36
+ end
37
+ # rubocop:enable Naming/UncommunicativeMethodParamName
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CMagick
4
+ VERSION = '0.2.0'
5
+ end
data/lib/cmagick.rb ADDED
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cmagick/version'
4
+ require 'rmagick'
5
+ require_relative './cmagick/rgb_to_ansi'
6
+
7
+ module CMagick
8
+ #
9
+ # cmagick = CMagick::LoadImage.new('/path/to/img.jpg')
10
+ # cmagick.show
11
+ #
12
+ # if img is big size
13
+ #
14
+ # cmagick.resize(0.1).show
15
+ #
16
+ class LoadImage
17
+ def initialize(img_path,
18
+ image: Magick::ImageList.new(img_path),
19
+ converter: RGBToANSI,
20
+ bg: "\x1b[48;5;")
21
+ @img_path = img_path
22
+ @image = image
23
+ @converter = converter
24
+ @bg = bg
25
+ end
26
+
27
+ def show
28
+ ansi_colors.each do |ansi_color|
29
+ ansi_color.each do |code|
30
+ print "#{color(code)} "
31
+ end
32
+ puts
33
+ end
34
+ puts
35
+ end
36
+
37
+ def resize(scale = 1.0)
38
+ LoadImage.new(@img_path,
39
+ image: @image.resize(scale),
40
+ converter: @converter,
41
+ bg: @bg)
42
+ end
43
+
44
+ def ansi_colors
45
+ pixels_2d.map do |pixels|
46
+ pixels.map { |r, g, b| @converter.call(r, g, b) }
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def pixels
53
+ @pixels ||=
54
+ @image.export_pixels.map { |pix| pix / 257 }.each_slice(3).to_a
55
+ end
56
+
57
+ def pixels_2d
58
+ @pixels_2d ||= pixels.each_slice(@image.columns)
59
+ end
60
+
61
+ def color(ansi_code)
62
+ "#{@bg}#{ansi_code}m"
63
+ end
64
+ end
65
+ end
data/resources/bar.png ADDED
Binary file
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmagick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - TsuMakoto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ To display the image programmatically,
15
+ - you can start the web application,
16
+ - save the image and display it again with the tool,
17
+ - or display it with the jupyter notebook.
18
+ However, for me, that one step is very troublesome.
19
+ So I created a tool that allows you to view the image as it is at the console at runtime.
20
+ email:
21
+ - tsukamoto@fusic.co.jp
22
+ executables: []
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - ".gitignore"
27
+ - ".rspec"
28
+ - ".travis.yml"
29
+ - CODE_OF_CONDUCT.md
30
+ - Gemfile
31
+ - Gemfile.lock
32
+ - README.md
33
+ - Rakefile
34
+ - bin/console
35
+ - bin/setup
36
+ - cmagick.gemspec
37
+ - lib/cmagick.rb
38
+ - lib/cmagick/rgb_to_ansi.rb
39
+ - lib/cmagick/version.rb
40
+ - resources/bar.png
41
+ homepage: https://github.com/TsuMakoto/cmagick/blob/master/README.md
42
+ licenses: []
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.0.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: A tool to display images on the console
63
+ test_files: []