catpix_mini 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.
- checksums.yaml +7 -0
- data/.gitignore +52 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/bin/catpix_mini +57 -0
- data/catpix_mini.gemspec +36 -0
- data/lib/catpix_mini.rb +72 -0
- data/lib/catpix_mini/private.rb +212 -0
- data/lib/catpix_mini/version.rb +7 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fbe7bb291ed03d1f3f945fe22fd96230016be3e1
|
4
|
+
data.tar.gz: 89b52d847d8e76dfa0c8aa69eabcfbb3fbfd7ace
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 259af61caf5768dd2eeea81ca932e840233206275036d36b8fd8afafaf0af569664c2f0e1713e584dacab118881350c4ddc07a6fdf70148df57544e00b1e7c44
|
7
|
+
data.tar.gz: 0051a1e22e34b494382ef415947e4f74e2edc30eb3669ddc51fb6872619773c30c5e9151eab056a04a020535b69ab9a93d5a06fe56df818810e7541bb76ead5a
|
data/.gitignore
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
/.config
|
5
|
+
/coverage/
|
6
|
+
/InstalledFiles
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/spec/examples.txt
|
10
|
+
/test/tmp/
|
11
|
+
/test/version_tmp/
|
12
|
+
/tmp/
|
13
|
+
|
14
|
+
# Used by dotenv library to load environment variables.
|
15
|
+
# .env
|
16
|
+
|
17
|
+
## Specific to RubyMotion:
|
18
|
+
.dat*
|
19
|
+
.repl_history
|
20
|
+
build/
|
21
|
+
*.bridgesupport
|
22
|
+
build-iPhoneOS/
|
23
|
+
build-iPhoneSimulator/
|
24
|
+
|
25
|
+
## Specific to RubyMotion (use of CocoaPods):
|
26
|
+
#
|
27
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
28
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
29
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
30
|
+
#
|
31
|
+
# vendor/Pods/
|
32
|
+
|
33
|
+
## Documentation cache and generated files:
|
34
|
+
/.yardoc/
|
35
|
+
/_yardoc/
|
36
|
+
/doc/
|
37
|
+
/rdoc/
|
38
|
+
|
39
|
+
## Environment normalization:
|
40
|
+
/.bundle/
|
41
|
+
/vendor/bundle
|
42
|
+
/lib/bundler/man/
|
43
|
+
|
44
|
+
# for a library or gem, you might want to ignore these files since the code is
|
45
|
+
# intended to run in multiple environments; otherwise, check them in:
|
46
|
+
Gemfile.lock
|
47
|
+
.ruby-version
|
48
|
+
.ruby-gemset
|
49
|
+
|
50
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
51
|
+
.rvmrc
|
52
|
+
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Radek Pazdera
|
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,47 @@
|
|
1
|
+
# Catpix_Minimagick_HD
|
2
|
+
|
3
|
+
Renders images in the terminal.
|
4
|
+
|
5
|
+
## Why not a fork but clone
|
6
|
+
|
7
|
+
This project is a "port" from [pazdera's catpix repo](https://github.com/pazdera/catpix).
|
8
|
+
The original project is based on RMagick while this one is based on MiniMagick. I was spending
|
9
|
+
time finding solutions with MiniMagick but could not find any hence I decided to port from the
|
10
|
+
original.
|
11
|
+
|
12
|
+

|
13
|
+
|
14
|
+
## More examples
|
15
|
+
|
16
|
+
For more examples and APIs please check out [pazdera's catpix repo](https://github.com/pazdera/catpix). They should be very similar at this point except that the binary name is changed from `catpix` to `catpix_mini`.
|
17
|
+
|
18
|
+
## Performances
|
19
|
+
|
20
|
+
MiniMagick is supposed to be lighter and faster since it provides only a thin wrapper around
|
21
|
+
the ImageMagick command-line toolset. I have done a bit of testing and find that catpix_mini
|
22
|
+
has upper advantage when rendering large image while catpix is slightly faster for smaller image.
|
23
|
+
|
24
|
+
|
25
|
+
time catpix ./img/benchmark.jpg
|
26
|
+
48.25s user 0.56s system 87% cpu 55.578 total
|
27
|
+
|
28
|
+
catpix_mini ./img/benchmark.jpg
|
29
|
+
42.26s user 0.76s system 83% cpu 51.647 total
|
30
|
+
|
31
|
+
|
32
|
+
Note: I have done not many benchmarks, and performance is not super important in my case. All
|
33
|
+
I need is to be able to include catpix in my powered-by-minimagick project. So please do some
|
34
|
+
more proper tests and let me know your results.
|
35
|
+
|
36
|
+
|
37
|
+
## Quality
|
38
|
+
|
39
|
+
RMagick return pixels colours in 16bits by default while MiniMagick is only 8 bits therefor the
|
40
|
+
quality at high-res looks slightly better in catpix compared to catpix-mini.
|
41
|
+
|
42
|
+
Only slightly because the quality printed out to terminal is not too insanely detailed to begin with.
|
43
|
+
|
44
|
+
|
45
|
+
## About Me
|
46
|
+
|
47
|
+
AJAX Amsterdamche and Chandler Bing's big fan.
|
data/Rakefile
ADDED
data/bin/catpix_mini
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2015 Radek Pazdera <me@radek.io>
|
4
|
+
# Distributed under the MIT License (see LICENSE.txt)
|
5
|
+
|
6
|
+
require 'docopt'
|
7
|
+
require 'catpix_mini'
|
8
|
+
|
9
|
+
doc = <<DOCOPT
|
10
|
+
Print images in the terminal.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
#{File.basename __FILE__} --help | --version
|
14
|
+
#{File.basename __FILE__} [options] <path>
|
15
|
+
|
16
|
+
Options:
|
17
|
+
-w=<width>, --limit-width Limit width of the image (factor of the size
|
18
|
+
of the terminal window) [default: 1].
|
19
|
+
-h=<height>, --limit-height Limit height of the image (factor of the size
|
20
|
+
of the terminal window) [default: 0],
|
21
|
+
-c=<pos>, --center Set x, y or xy centering in the window.
|
22
|
+
-b=<colour>, --bg Set background colour.
|
23
|
+
-f, --bg-fill Draw background around the image as well.
|
24
|
+
-r=<res>, --resolution Either 'high' or 'low' [default: auto].
|
25
|
+
|
26
|
+
--help Show this message.
|
27
|
+
--version Print the version.
|
28
|
+
DOCOPT
|
29
|
+
|
30
|
+
begin
|
31
|
+
args = Docopt::docopt doc, :version => CatpixMini::VERSION
|
32
|
+
rescue Docopt::Exit => e
|
33
|
+
$stderr.puts e.message
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
options = {
|
38
|
+
:limit_x => args['--limit-width'].to_f,
|
39
|
+
:limit_y => args['--limit-height'].to_f,
|
40
|
+
:bg_fill => args['--bg-fill'],
|
41
|
+
:resolution => args['--resolution']
|
42
|
+
}
|
43
|
+
|
44
|
+
if args['--center']
|
45
|
+
options[:center_x] = true if args['--center'].include? 'x'
|
46
|
+
options[:center_y] = true if args['--center'].include? 'y'
|
47
|
+
|
48
|
+
if not args['--center'].include? 'x' or not args['--center'].include? 'x'
|
49
|
+
$stderr.puts "Error: Invalid --center argument. Use x, y or xy."
|
50
|
+
$stderr.puts doc
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
options[:bg] = args['--bg'] if args['--bg']
|
55
|
+
|
56
|
+
CatpixMini::print_image args['<path>'], options
|
57
|
+
exit 0
|
data/catpix_mini.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'catpix_mini/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "catpix_mini"
|
8
|
+
spec.version = CatpixMini::VERSION
|
9
|
+
spec.authors = ["Radek Pazdera", "Huy Dinh"]
|
10
|
+
spec.email = ["me@radek.io", "phradion@gmail.com"]
|
11
|
+
spec.summary = %q{Cat images into the terminal. A port to work with MiniMagick}
|
12
|
+
spec.description = %q{Print images (png, jpg, gif and many others) in the
|
13
|
+
command line with ease. Using rmagick and tco in the
|
14
|
+
background to read the images and convert them into
|
15
|
+
the extended 256 colour palette for terminals.
|
16
|
+
This gem is ported from original catpix gem to be
|
17
|
+
compatible with MiniMagick instead of RMagick. It will
|
18
|
+
also be faster when rendering large images.}
|
19
|
+
spec.homepage = "https://github.com/phradion/catpix_mini_HD"
|
20
|
+
spec.license = "MIT"
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0")
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.required_ruby_version = ">= 1.9"
|
28
|
+
|
29
|
+
spec.add_runtime_dependency "tco", "~> 0.1", ">= 0.1.8"
|
30
|
+
spec.add_runtime_dependency "mini_magick", "~> 4.7.0", ">= 4.7.0"
|
31
|
+
spec.add_dependency "docopt", "~> 0.5", ">= 0.5.0"
|
32
|
+
spec.add_dependency "ruby-terminfo", "~> 0.1", ">= 0.1.1"
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
36
|
+
end
|
data/lib/catpix_mini.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Copyright (c) 2015 Radek Pazdera <me@radek.io>
|
2
|
+
# Distributed under the MIT License (see LICENSE.txt)
|
3
|
+
# Ported to use mini_magick (c) 2017 Huy Dinh <phradion@gmail.com>
|
4
|
+
|
5
|
+
require "catpix_mini/version"
|
6
|
+
require "catpix_mini/private"
|
7
|
+
|
8
|
+
# Provides a function to print images in the terminal. A range of different
|
9
|
+
# formats is supported (check out what ImageMagick supports). Under the hood,
|
10
|
+
# this module uses two components:
|
11
|
+
#
|
12
|
+
# * [rmagick](https://rmagick.github.io/) to read and scale the images and
|
13
|
+
# * [tco](https://github.com/pazdera/tco) to map their pixels on the extended
|
14
|
+
# colour palette in the terminal.
|
15
|
+
#
|
16
|
+
# Some other minor features like centering and handling background colours
|
17
|
+
# are supplied directly by this module.
|
18
|
+
module CatpixMini
|
19
|
+
# Print an image to the terminal.
|
20
|
+
#
|
21
|
+
# All formats supported by ImageMagick are supported. The image's colours
|
22
|
+
# will be mapped onto the extended 256 colour palette. Also by default, it
|
23
|
+
# will be scaled down to fit the width of the terminal while keeping its
|
24
|
+
# proportions. This can be changed using the `options` parameter.
|
25
|
+
#
|
26
|
+
# @param [Hash] options Adjust some parameters of the image when printed.
|
27
|
+
# @option options [Float] :limit_x A factor of the terminal window's width.
|
28
|
+
# If present, the image will be scaled down
|
29
|
+
# to fit (proportions are kept). Using 0
|
30
|
+
# will disable the scaling. [default: 1.0]
|
31
|
+
# @option options [Float] :limit_y A factor of the terminal window's height.
|
32
|
+
# If present, the image will be scaled down
|
33
|
+
# to fit (proportions are kept). Using 0
|
34
|
+
# will disable the scaling. [default: 0]
|
35
|
+
# @option options [Boolean] :center_x Center the image horizontally in the
|
36
|
+
# terminal window. [default: false]
|
37
|
+
# @option options [Boolean] :center_y Center the image vertically in the
|
38
|
+
# terminal window. [default: false]
|
39
|
+
# @option options [String] :bg Background colour to use in case there are
|
40
|
+
# any fully transparent pixels in the image.
|
41
|
+
# This can be a RGB value '#c0ffee' or a tco
|
42
|
+
# alias 'red' or 'blue'. [default: nil]
|
43
|
+
# @option options [Boolean] :bg_fill Fill the margins around the image with
|
44
|
+
# background colour. [default: false]
|
45
|
+
# @option options [String] :resolution Determines the pixel size of the
|
46
|
+
# rendered image. Can be set to `high`,
|
47
|
+
# `low` or `auto` (default). If set to
|
48
|
+
# `auto` the resolution will be picked
|
49
|
+
# automatically based on your terminal's
|
50
|
+
# support of unicode.
|
51
|
+
def self.print_image(path, options={})
|
52
|
+
|
53
|
+
options = default_options.merge! options
|
54
|
+
|
55
|
+
if options[:resolution] == 'auto'
|
56
|
+
options[:resolution] = can_use_utf8? ? 'high' : 'low'
|
57
|
+
end
|
58
|
+
@@resolution = options[:resolution]
|
59
|
+
|
60
|
+
img = load_image path
|
61
|
+
resize! img, options[:limit_x], options[:limit_y]
|
62
|
+
|
63
|
+
margins = get_margins img, options[:center_x], options[:center_y]
|
64
|
+
margins[:colour] = options[:bg_fill] ? options[:bg] : nil
|
65
|
+
|
66
|
+
if high_res?
|
67
|
+
do_print_image_hr img, margins, options
|
68
|
+
else
|
69
|
+
do_print_image_lr img, margins, options
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,212 @@
|
|
1
|
+
# Copyright (c) 2015 Radek Pazdera <me@radek.io>
|
2
|
+
# Distributed under the MIT License (see LICENSE.txt)
|
3
|
+
# Ported to use mini_magick (c) 2017 Huy Dinh <phradion@gmail.com>
|
4
|
+
|
5
|
+
require "mini_magick"
|
6
|
+
require "tco"
|
7
|
+
require "terminfo"
|
8
|
+
|
9
|
+
module CatpixMini
|
10
|
+
private
|
11
|
+
MAX_OPACITY = 65535
|
12
|
+
|
13
|
+
def self.default_options
|
14
|
+
{
|
15
|
+
limit_x: 1.0,
|
16
|
+
limit_y: 0,
|
17
|
+
center_x: false,
|
18
|
+
center_y: false,
|
19
|
+
bg: nil,
|
20
|
+
bg_fill: false,
|
21
|
+
resolution: 'auto'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
@@resolution = nil
|
26
|
+
|
27
|
+
def self.high_res?
|
28
|
+
@@resolution == 'high'
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.can_use_utf8?
|
32
|
+
ENV.values_at("LC_ALL", "LC_CTYPE", "LANG").compact.first.include?("UTF-8")
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.prep_lr_pixel(colour)
|
36
|
+
colour ? " ".bg(colour) : " "
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.print_lr_pixel(colour)
|
40
|
+
print prep_lr_pixel colour
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.prep_hr_pixel(colour_top, colour_bottom)
|
44
|
+
upper = "\u2580"
|
45
|
+
lower = "\u2584"
|
46
|
+
|
47
|
+
return " " if colour_bottom.nil? and colour_top.nil?
|
48
|
+
return lower.fg colour_bottom if colour_top.nil?
|
49
|
+
return upper.fg colour_top if colour_bottom.nil?
|
50
|
+
|
51
|
+
c_top = Tco::match_colour colour_top
|
52
|
+
c_bottom = Tco::match_colour colour_bottom
|
53
|
+
if c_top == c_bottom
|
54
|
+
return " ".bg "@#{c_top}"
|
55
|
+
end
|
56
|
+
|
57
|
+
upper.fg("@#{c_top}").bg("@#{c_bottom}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.print_hr_pixel(colour_top, colour_bottom)
|
61
|
+
print prep_hr_pixel colour_top, colour_bottom
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns normalised size of the terminal window
|
65
|
+
#
|
66
|
+
# Catpix can use either two blank spaces to approximate a pixel in the
|
67
|
+
# temrinal or the 'upper half block' and 'bottom half block' characters.
|
68
|
+
#
|
69
|
+
# Depending on which of the above will be used, the screen size
|
70
|
+
# must be normalised accordingly.
|
71
|
+
def self.get_screen_size
|
72
|
+
th, tw = TermInfo.screen_size
|
73
|
+
if high_res? then [tw, th * 2] else [tw / 2, th] end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.load_image(path)
|
77
|
+
MiniMagick::Image.open(path)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Scale the image down based on the limits while keeping the aspect ratio
|
81
|
+
def self.resize!(img, limit_x=0, limit_y=0)
|
82
|
+
tw, th = get_screen_size
|
83
|
+
iw = img[:width]
|
84
|
+
ih = img[:height]
|
85
|
+
|
86
|
+
width = limit_x > 0 ? (tw * limit_x).to_i : iw
|
87
|
+
height = limit_y > 0 ? (th * limit_y).to_i : ih
|
88
|
+
|
89
|
+
# Resize the image if it's bigger than the limited viewport
|
90
|
+
if iw > width or ih > height
|
91
|
+
img.resize "#{width}x#{height}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Determine the margins based on the centering options
|
96
|
+
def self.get_margins(img, center_x, center_y)
|
97
|
+
margins = {}
|
98
|
+
tw, th = get_screen_size
|
99
|
+
|
100
|
+
x_space = tw - img[:width]
|
101
|
+
if center_x
|
102
|
+
margins[:left] = x_space / 2
|
103
|
+
margins[:right] = x_space / 2 + x_space % 2
|
104
|
+
else
|
105
|
+
margins[:left] = 0
|
106
|
+
margins[:right] = x_space
|
107
|
+
end
|
108
|
+
|
109
|
+
y_space = th - img[:height]
|
110
|
+
if center_y
|
111
|
+
margins[:top] = y_space / 2
|
112
|
+
margins[:bottom] = y_space / 2 + y_space % 2
|
113
|
+
else
|
114
|
+
margins[:top] = 0
|
115
|
+
margins[:bottom] = 0
|
116
|
+
end
|
117
|
+
|
118
|
+
if high_res? and margins[:top] % 2 and margins[:bottom] % 2
|
119
|
+
margins[:top] -= 1
|
120
|
+
margins[:bottom] += 1
|
121
|
+
end
|
122
|
+
|
123
|
+
margins
|
124
|
+
end
|
125
|
+
|
126
|
+
#############################################################################
|
127
|
+
# "DRAWING" METHODS
|
128
|
+
#############################################################################
|
129
|
+
|
130
|
+
def self.prep_vert_margin(size, colour)
|
131
|
+
tw = get_screen_size
|
132
|
+
|
133
|
+
buffer = ""
|
134
|
+
if high_res?
|
135
|
+
(size / 2).times do
|
136
|
+
sub_buffer = ""
|
137
|
+
tw.times { sub_buffer += prep_hr_pixel nil, nil }
|
138
|
+
buffer += sub_buffer.bg(colour) + "\n"
|
139
|
+
end
|
140
|
+
else
|
141
|
+
size.times do
|
142
|
+
sub_buffer = ""
|
143
|
+
tw.times { sub_buffer += prep_lr_pixel nil }
|
144
|
+
buffer += sub_buffer.bg(colour) + "\n"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
buffer
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.prep_horiz_margin(size, colour)
|
151
|
+
buffer = ""
|
152
|
+
if high_res?
|
153
|
+
size.times { buffer += prep_hr_pixel nil, nil }
|
154
|
+
else
|
155
|
+
size.times { buffer += prep_lr_pixel nil }
|
156
|
+
end
|
157
|
+
buffer.bg colour
|
158
|
+
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# Print the image in low resolution
|
162
|
+
def self.do_print_image_lr(img, margins, options)
|
163
|
+
pixels = img.get_pixels
|
164
|
+
rows = img[:height]
|
165
|
+
cols = pixels[0].length
|
166
|
+
|
167
|
+
print prep_vert_margin margins[:top], margins[:colour]
|
168
|
+
|
169
|
+
0.upto(rows - 1) do |row|
|
170
|
+
buffer = prep_horiz_margin margins[:left], margins[:colour]
|
171
|
+
0.upto(cols - 1) do |col|
|
172
|
+
pixel = pixels[row][col]
|
173
|
+
buffer += prep_lr_pixel pixel
|
174
|
+
end
|
175
|
+
buffer += prep_horiz_margin margins[:right], margins[:colour]
|
176
|
+
puts buffer
|
177
|
+
end
|
178
|
+
|
179
|
+
print prep_vert_margin margins[:bottom], margins[:colour]
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
##
|
184
|
+
# Print the image in high resolution (using unicode's upper half block)
|
185
|
+
def self.do_print_image_hr(img, margins, options)
|
186
|
+
pixels = img.get_pixels
|
187
|
+
rows = img[:height]
|
188
|
+
cols = pixels[0].length
|
189
|
+
|
190
|
+
|
191
|
+
print prep_vert_margin margins[:top], margins[:colour]
|
192
|
+
|
193
|
+
0.step(rows - 1, 2) do |row|
|
194
|
+
# line buffering makes it about 20% faster
|
195
|
+
buffer = prep_horiz_margin margins[:left], margins[:colour]
|
196
|
+
0.upto(cols - 1) do |col|
|
197
|
+
top_pixel = pixels[row][col]
|
198
|
+
colour_top = top_pixel
|
199
|
+
|
200
|
+
bottom_pixel = pixels[row+1][col]
|
201
|
+
colour_bottom = bottom_pixel
|
202
|
+
|
203
|
+
buffer += prep_hr_pixel colour_top, colour_bottom
|
204
|
+
end
|
205
|
+
buffer += prep_horiz_margin margins[:right], margins[:colour]
|
206
|
+
puts buffer
|
207
|
+
end
|
208
|
+
|
209
|
+
print prep_vert_margin margins[:bottom], margins[:colour]
|
210
|
+
|
211
|
+
end
|
212
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: catpix_mini
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Radek Pazdera
|
8
|
+
- Huy Dinh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: tco
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.1'
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.8
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - "~>"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0.1'
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.8
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: mini_magick
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.7.0
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 4.7.0
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 4.7.0
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 4.7.0
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: docopt
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.5'
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.5.0
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0.5'
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.5.0
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: ruby-terminfo
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0.1'
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.1.1
|
84
|
+
type: :runtime
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0.1'
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.1.1
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: bundler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '1.6'
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '1.6'
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
name: rake
|
110
|
+
requirement: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '10.4'
|
115
|
+
type: :development
|
116
|
+
prerelease: false
|
117
|
+
version_requirements: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '10.4'
|
122
|
+
description: |-
|
123
|
+
Print images (png, jpg, gif and many others) in the
|
124
|
+
command line with ease. Using rmagick and tco in the
|
125
|
+
background to read the images and convert them into
|
126
|
+
the extended 256 colour palette for terminals.
|
127
|
+
This gem is ported from original catpix gem to be
|
128
|
+
compatible with MiniMagick instead of RMagick. It will
|
129
|
+
also be faster when rendering large images.
|
130
|
+
email:
|
131
|
+
- me@radek.io
|
132
|
+
- phradion@gmail.com
|
133
|
+
executables:
|
134
|
+
- catpix_mini
|
135
|
+
extensions: []
|
136
|
+
extra_rdoc_files: []
|
137
|
+
files:
|
138
|
+
- ".gitignore"
|
139
|
+
- CHANGELOG.md
|
140
|
+
- Gemfile
|
141
|
+
- LICENSE.txt
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- bin/catpix_mini
|
145
|
+
- catpix_mini.gemspec
|
146
|
+
- lib/catpix_mini.rb
|
147
|
+
- lib/catpix_mini/private.rb
|
148
|
+
- lib/catpix_mini/version.rb
|
149
|
+
homepage: https://github.com/phradion/catpix_mini_HD
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '1.9'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.6.12
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: Cat images into the terminal. A port to work with MiniMagick
|
173
|
+
test_files: []
|