ansify 0.0.1 → 0.0.2
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.
- data/README.md +19 -10
- data/ansify.gemspec +5 -1
- data/bin/ansify +30 -24
- metadata +35 -2
data/README.md
CHANGED
@@ -1,27 +1,36 @@
|
|
1
1
|
ansify
|
2
2
|
======
|
3
3
|
|
4
|
-
A command-line tool to convert
|
4
|
+
A command-line tool to convert images to ANSI escape codes.
|
5
5
|
|
6
6
|
Installation
|
7
7
|
------------
|
8
8
|
|
9
|
-
|
9
|
+
gem install ansify
|
10
10
|
|
11
11
|
Usage
|
12
12
|
-----
|
13
13
|
|
14
14
|
> ansify --help
|
15
|
-
ansify v0.0.
|
15
|
+
ansify v0.0.2
|
16
16
|
Options:
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
--image, -i <s>: Image to ansify
|
18
|
+
--scale, -s <f>: Scale factor
|
19
|
+
--sampling, -a: Scale image using pixel sampling
|
20
|
+
--output, -o <s>: Output file
|
20
21
|
--version, -v: Print version and exit
|
21
22
|
--help, -h: Show this message
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
Try this
|
25
|
+
|
26
|
+
ansify --image https://github.com/enricruiz/ansify/raw/master/examples/nyan.png
|
27
|
+
|
28
|
+
ansify --image https://github.com/enricruiz/ansify/raw/master/examples/nyan.png --scale 0.5
|
29
|
+
|
30
|
+
ansify --image https://github.com/enricruiz/ansify/raw/master/examples/nyan.png --scale 0.5 --sampling
|
31
|
+
|
32
|
+
Example output
|
33
|
+
---------------
|
34
|
+
|
35
|
+

|
25
36
|
|
26
|
-
* Add file output
|
27
|
-
* Handle resampling to higher resolution
|
data/ansify.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ansify'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.2'
|
4
4
|
s.date = '2012-02-08'
|
5
5
|
s.summary = "Covert PNG images to ANSI escape codes"
|
6
6
|
s.description = "A command-line tool to convert PNG images to ANSI escape codes."
|
@@ -10,6 +10,10 @@ Gem::Specification.new do |s|
|
|
10
10
|
|
11
11
|
s.executables = ["ansify"]
|
12
12
|
|
13
|
+
s.add_dependency "trollop"
|
14
|
+
s.add_dependency "rainbow"
|
15
|
+
s.add_dependency "rmagick"
|
16
|
+
|
13
17
|
s.files = %w[
|
14
18
|
README.md
|
15
19
|
Rakefile
|
data/bin/ansify
CHANGED
@@ -1,45 +1,51 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'RMagick'
|
4
4
|
require 'rainbow'
|
5
5
|
require 'trollop'
|
6
6
|
|
7
|
-
VERSION = "0.0.
|
7
|
+
VERSION = "0.0.2"
|
8
8
|
|
9
9
|
options = Trollop::options do
|
10
10
|
version "ansify v#{VERSION}"
|
11
11
|
|
12
|
-
opt :
|
13
|
-
opt :
|
14
|
-
opt :
|
12
|
+
opt :image, "Image to ansify", :type => String
|
13
|
+
opt :scale, "Scale factor", :type => :float
|
14
|
+
opt :sampling, "Scale image using pixel sampling", :default => false
|
15
|
+
opt :output, "Output file", :type => String
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
Trollop::die :resize, "> 0 and < 100" unless (1..99).include? options[:resize] if options[:resize]
|
18
|
+
image = Magick::Image.read(options[:image]).first
|
19
19
|
|
20
|
-
|
20
|
+
width = image.columns
|
21
|
+
height = image.rows
|
21
22
|
|
22
|
-
if options[:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
if options[:nearest]
|
27
|
-
image = image.resample_nearest_neighbor(w, h)
|
23
|
+
if options[:scale]
|
24
|
+
if options[:sampling]
|
25
|
+
image = image.sample(options[:scale])
|
28
26
|
elsif
|
29
|
-
image = image.
|
27
|
+
image = image.scale(options[:scale])
|
30
28
|
end
|
29
|
+
|
30
|
+
width = image.columns
|
31
|
+
height = image.rows
|
32
|
+
end
|
33
|
+
|
34
|
+
output = $stdout
|
35
|
+
|
36
|
+
if options[:output]
|
37
|
+
output = File.open(options[:output], 'w')
|
31
38
|
end
|
32
39
|
|
33
|
-
(0..
|
34
|
-
(0..
|
35
|
-
pixel = image
|
36
|
-
|
37
|
-
|
38
|
-
b = ChunkyPNG::Color.b(pixel)
|
39
|
-
a = ChunkyPNG::Color.a(pixel)
|
40
|
+
(0..height).each do |y|
|
41
|
+
(0..width).each do |x|
|
42
|
+
pixel = image.pixel_color(x, y)
|
43
|
+
opacity = pixel.opacity
|
44
|
+
color = pixel.to_color(Magick::AllCompliance, false, 8, true)
|
40
45
|
|
41
|
-
|
46
|
+
colorize = (opacity == 0)
|
47
|
+
output.print colorize ? " ".background(color) : " "
|
42
48
|
end
|
43
|
-
print "\n"
|
49
|
+
output.print "\n"
|
44
50
|
end
|
45
51
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,40 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-02-08 00:00:00.000000000Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: trollop
|
16
|
+
requirement: &7692160 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *7692160
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rainbow
|
27
|
+
requirement: &7691720 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *7691720
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rmagick
|
38
|
+
requirement: &7691300 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *7691300
|
14
47
|
description: A command-line tool to convert PNG images to ANSI escape codes.
|
15
48
|
email: enric.ruizmartinez@gmail.com
|
16
49
|
executables:
|