ansify 0.0.1
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 +27 -0
- data/Rakefile +10 -0
- data/ansify.gemspec +19 -0
- data/bin/ansify +45 -0
- metadata +49 -0
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
ansify
|
2
|
+
======
|
3
|
+
|
4
|
+
A command-line tool to convert PNG images to ANSI escape codes.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
sudo gem install ansify
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
|
14
|
+
> ansify --help
|
15
|
+
ansify v0.0.1
|
16
|
+
Options:
|
17
|
+
--file, -f <s>: PNG file to convert
|
18
|
+
--resize, -r <i>: Resize image in % [1, 99]
|
19
|
+
--nearest, -n: Resize using nearest neighbor sampling instead of bilinear sampling
|
20
|
+
--version, -v: Print version and exit
|
21
|
+
--help, -h: Show this message
|
22
|
+
|
23
|
+
Todo
|
24
|
+
----
|
25
|
+
|
26
|
+
* Add file output
|
27
|
+
* Handle resampling to higher resolution
|
data/Rakefile
ADDED
data/ansify.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ansify'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2012-02-08'
|
5
|
+
s.summary = "Covert PNG images to ANSI escape codes"
|
6
|
+
s.description = "A command-line tool to convert PNG images to ANSI escape codes."
|
7
|
+
s.authors = ["Enric Ruiz"]
|
8
|
+
s.email = 'enric.ruizmartinez@gmail.com'
|
9
|
+
s.homepage = 'https://github.com/enricruiz/ansify'
|
10
|
+
|
11
|
+
s.executables = ["ansify"]
|
12
|
+
|
13
|
+
s.files = %w[
|
14
|
+
README.md
|
15
|
+
Rakefile
|
16
|
+
bin/ansify
|
17
|
+
ansify.gemspec
|
18
|
+
]
|
19
|
+
end
|
data/bin/ansify
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'chunky_png'
|
4
|
+
require 'rainbow'
|
5
|
+
require 'trollop'
|
6
|
+
|
7
|
+
VERSION = "0.0.1"
|
8
|
+
|
9
|
+
options = Trollop::options do
|
10
|
+
version "ansify v#{VERSION}"
|
11
|
+
|
12
|
+
opt :file, "PNG file to convert", :type => String
|
13
|
+
opt :resize, "Resize image in % [1, 99]", :type => :int
|
14
|
+
opt :nearest, "Resize using nearest neighbor sampling instead of bilinear sampling"
|
15
|
+
end
|
16
|
+
|
17
|
+
Trollop::die :file, "must exist" unless File.exist?(options[:file]) if options[:file]
|
18
|
+
Trollop::die :resize, "> 0 and < 100" unless (1..99).include? options[:resize] if options[:resize]
|
19
|
+
|
20
|
+
image = ChunkyPNG::Image.from_file(options[:file])
|
21
|
+
|
22
|
+
if options[:resize]
|
23
|
+
w = image.dimension.width - (image.dimension.width * options[:resize] / 100)
|
24
|
+
h = image.dimension.height - (image.dimension.height * options[:resize] / 100)
|
25
|
+
|
26
|
+
if options[:nearest]
|
27
|
+
image = image.resample_nearest_neighbor(w, h)
|
28
|
+
elsif
|
29
|
+
image = image.resample_bilinear(w, h)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
(0..image.dimension.height - 1).each do |y|
|
34
|
+
(0..image.dimension.width - 1).each do |x|
|
35
|
+
pixel = image[x, y]
|
36
|
+
r = ChunkyPNG::Color.r(pixel)
|
37
|
+
g = ChunkyPNG::Color.g(pixel)
|
38
|
+
b = ChunkyPNG::Color.b(pixel)
|
39
|
+
a = ChunkyPNG::Color.a(pixel)
|
40
|
+
|
41
|
+
print a > 128 ? " ".background(r, g, b) : " "
|
42
|
+
end
|
43
|
+
print "\n"
|
44
|
+
end
|
45
|
+
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ansify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Enric Ruiz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-08 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: A command-line tool to convert PNG images to ANSI escape codes.
|
15
|
+
email: enric.ruizmartinez@gmail.com
|
16
|
+
executables:
|
17
|
+
- ansify
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- bin/ansify
|
24
|
+
- ansify.gemspec
|
25
|
+
homepage: https://github.com/enricruiz/ansify
|
26
|
+
licenses: []
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 1.8.15
|
46
|
+
signing_key:
|
47
|
+
specification_version: 3
|
48
|
+
summary: Covert PNG images to ANSI escape codes
|
49
|
+
test_files: []
|