termpic 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +24 -0
- data/Rakefile +1 -0
- data/bin/termpic +13 -0
- data/lib/termpic.rb +8 -0
- data/lib/termpic/ansi_rgb.rb +21 -0
- data/lib/termpic/image.rb +86 -0
- data/lib/termpic/version.rb +3 -0
- data/public/sample.png +0 -0
- data/spec/sample/octocat.jpg +0 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/termpic/image_spec.rb +16 -0
- data/spec/termpic_spec.rb +9 -0
- data/termpic.gemspec +24 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7aeded193508cf383777bc666f87f77a3f1f8a82
|
4
|
+
data.tar.gz: 2782f0f23cba9580c1894741984004ac28e972cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7e4ae9630bf2799ca6b381d15a5989f2636b856474fb999cd6d030eeabdd9d71341c8e96212ac6ee1e61957bb6fb95e08dae199f4b70b8485e7d61fa9a181c6
|
7
|
+
data.tar.gz: 1d4e972995854f15ceb17352ea7ee89895a02852550d0e650f83fe251eb03da8acc74d8bc88246c311248d62a17816f8de2b27ed42f4a00fbf7ef8690071cb13
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
## Termpic 0.0.5 (2013-02-24)
|
2
|
+
|
3
|
+
* add --domain option for alternate `open`
|
4
|
+
* extract to "-d" option to using double spaces
|
5
|
+
|
6
|
+
## Termpic 0.0.4 (2013-02-12)
|
7
|
+
|
8
|
+
* fix showing resized size bug when both of "-s" and "-f"
|
9
|
+
* remove dependency to rainbow gem
|
10
|
+
* use double spaces for drawing
|
11
|
+
|
12
|
+
## Termpic 0.0.3 (2013-02-05)
|
13
|
+
|
14
|
+
* add -s option to show images cols and rows
|
15
|
+
|
16
|
+
## Termpic 0.0.2 (2013-01-12)
|
17
|
+
|
18
|
+
* add -f option to fit terminal
|
19
|
+
|
20
|
+
## Termpic 0.0.1 (2013-01-12)
|
21
|
+
|
22
|
+
* initial release
|
23
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 onk
|
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,24 @@
|
|
1
|
+
Termpic
|
2
|
+
================================
|
3
|
+
|
4
|
+
Display images in terminal using ANSI background color.
|
5
|
+
|
6
|
+
![sample](https://raw.github.com/onk/termpic/master/public/sample.png)
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------------------------------------------------------------------
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install termpic
|
13
|
+
```
|
14
|
+
|
15
|
+
Author
|
16
|
+
------------------------------------------------------------------------
|
17
|
+
|
18
|
+
onk <takafumi.onaka@gmail.com> (@onk)
|
19
|
+
|
20
|
+
License
|
21
|
+
------------------------------------------------------------------------
|
22
|
+
|
23
|
+
Licensed under the MIT license.
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/termpic
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require "optparse"
|
3
|
+
require "termpic"
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
opt = OptionParser.new
|
7
|
+
opt.on('-f') {|v| options[:fit_terminal] = true }
|
8
|
+
opt.on('-s') {|v| options[:show_size] = true }
|
9
|
+
opt.on('-d') {|v| options[:double] = true }
|
10
|
+
opt.on('--domain=VAL') {|v| options[:domain] = v }
|
11
|
+
opt.parse!(ARGV)
|
12
|
+
Termpic::Image.new(ARGV[0], options).draw
|
13
|
+
|
data/lib/termpic.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Termpic
|
2
|
+
class AnsiRgb
|
3
|
+
def self.wrap_with_code(string, rgb)
|
4
|
+
red, green, blue = rgb[0], rgb[1], rgb[2]
|
5
|
+
"\e[#{code(red, green, blue)}m" + string + "\e[0m"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.code(red, green, blue)
|
9
|
+
index = 16 +
|
10
|
+
to_ansi_domain(red) * 36 +
|
11
|
+
to_ansi_domain(green) * 6 +
|
12
|
+
to_ansi_domain(blue)
|
13
|
+
"48;5;#{index}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.to_ansi_domain(value)
|
17
|
+
(6 * (value / 256.0)).to_i
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Termpic
|
2
|
+
class Image
|
3
|
+
def initialize(path, options = {})
|
4
|
+
@image = Magick::ImageList.new(path)
|
5
|
+
@fit_terminal = !!options[:fit_terminal]
|
6
|
+
@show_size = !!options[:show_size]
|
7
|
+
@double = !!options[:double]
|
8
|
+
@path = path
|
9
|
+
@domain = options[:domain]
|
10
|
+
end
|
11
|
+
|
12
|
+
def draw
|
13
|
+
convert_to_fit_terminal_size if @fit_terminal
|
14
|
+
rgb_analyze
|
15
|
+
ansi_analyze
|
16
|
+
puts_ansi
|
17
|
+
puts_size if @show_size
|
18
|
+
puts_url if @domain
|
19
|
+
end
|
20
|
+
|
21
|
+
def convert_to_fit_terminal_size
|
22
|
+
term_height, term_width = get_term_size
|
23
|
+
term_width = term_width / 2 if @double
|
24
|
+
@orig_image = @image
|
25
|
+
@image = @image.resize_to_fit(term_width, term_height)
|
26
|
+
end
|
27
|
+
|
28
|
+
def rgb_analyze
|
29
|
+
@rgb = []
|
30
|
+
cols = @image.columns
|
31
|
+
rows = @image.rows
|
32
|
+
rows.times do |y|
|
33
|
+
cols.times do |x|
|
34
|
+
@rgb[y] ||= []
|
35
|
+
pixcel = @image.pixel_color(x, y)
|
36
|
+
r = pixcel.red / 256
|
37
|
+
g = pixcel.green / 256
|
38
|
+
b = pixcel.blue / 256
|
39
|
+
@rgb[y] << [r, g, b]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def ansi_analyze
|
45
|
+
raise "use rgb_analyze before ansi_analyze" unless @rgb
|
46
|
+
ret = []
|
47
|
+
@rgb.map! do |row|
|
48
|
+
ret << row.map{|pixcel|
|
49
|
+
AnsiRgb.wrap_with_code(@double ? " " : " ", pixcel)
|
50
|
+
}.join
|
51
|
+
end
|
52
|
+
@ansi = ret.join("\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
def puts_ansi
|
56
|
+
raise "use ansi_analyze before to_ansi" unless @ansi
|
57
|
+
puts @ansi
|
58
|
+
end
|
59
|
+
|
60
|
+
def puts_size
|
61
|
+
if @orig_image
|
62
|
+
puts "#{@orig_image.columns}x#{@orig_image.rows}"
|
63
|
+
else
|
64
|
+
puts "#{@image.columns}x#{@image.rows}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def puts_url
|
69
|
+
public_marker_dirs = ["public", "assets"]
|
70
|
+
full_path = File.absolute_path(@path)
|
71
|
+
dirs = full_path.split(File::SEPARATOR)
|
72
|
+
idx = dirs.rindex{|dir| public_marker_dirs.include?(dir) }
|
73
|
+
case dirs[idx]
|
74
|
+
when "public"
|
75
|
+
puts "http://#{@domain}/#{dirs[idx+1 .. -1].join("/")}"
|
76
|
+
when "assets"
|
77
|
+
puts "http://#{@domain}/#{dirs[idx .. -1].join("/")}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_term_size
|
82
|
+
`stty size`.split(" ").map(&:to_i)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
data/public/sample.png
ADDED
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe Termpic::Image do
|
3
|
+
describe "#initialize" do
|
4
|
+
it { Termpic::Image.new(TermpicTestImage::SAMPLE_IMAGE_PATH).should_not be_nil }
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#draw" do
|
8
|
+
before{
|
9
|
+
@image = Termpic::Image.new(TermpicTestImage::SAMPLE_IMAGE_PATH)
|
10
|
+
}
|
11
|
+
it "" do
|
12
|
+
@image.draw
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/termpic.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'termpic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "termpic"
|
8
|
+
gem.version = Termpic::VERSION
|
9
|
+
gem.authors = ["onk"]
|
10
|
+
gem.email = ["takafumi.onaka@gmail.com"]
|
11
|
+
gem.description = "Display images in terminal."
|
12
|
+
gem.summary = "Display images in terminal."
|
13
|
+
gem.homepage = "https://github.com/onk/termpic"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
gem.add_dependency "rmagick"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: termpic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- onk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rmagick
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Display images in terminal.
|
56
|
+
email:
|
57
|
+
- takafumi.onaka@gmail.com
|
58
|
+
executables:
|
59
|
+
- termpic
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/termpic
|
71
|
+
- lib/termpic.rb
|
72
|
+
- lib/termpic/ansi_rgb.rb
|
73
|
+
- lib/termpic/image.rb
|
74
|
+
- lib/termpic/version.rb
|
75
|
+
- public/sample.png
|
76
|
+
- spec/sample/octocat.jpg
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/termpic/image_spec.rb
|
79
|
+
- spec/termpic_spec.rb
|
80
|
+
- termpic.gemspec
|
81
|
+
homepage: https://github.com/onk/termpic
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.0.0.rc.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Display images in terminal.
|
105
|
+
test_files:
|
106
|
+
- spec/sample/octocat.jpg
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/termpic/image_spec.rb
|
109
|
+
- spec/termpic_spec.rb
|