honeybii 1.0.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/bin/honeybii +35 -0
- data/lib/honeybii.rb +2 -0
- data/lib/honeybii/ascii_image.rb +21 -0
- data/lib/honeybii/shaded_image.rb +49 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5aeb2dec0785ed14c0020b648e35184db6dc0fd0
|
4
|
+
data.tar.gz: 8be980047f6b3f6467ade5ef60c07053d7923347
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8371437aa6d89deff5ef712986969485031e5da558ed39971def1fead8ea6c26798986a6ca536b57e81dcc22ea5aa239846eea03d235c4cd92a1a606da544534
|
7
|
+
data.tar.gz: e003e5c01426712b341525f97c0066b7f87a9e2cf9d13d06a120c816a0604dee38bf946963bdd83415e4488752faa46f4ff281b3871a45382832fd61495c9750
|
data/bin/honeybii
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'rmagick'
|
4
|
+
|
5
|
+
require 'honeybii'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
option_parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = 'Usage: honeybii.rb [options]'
|
10
|
+
|
11
|
+
opts.on('-i', '--image FILENAME', 'Name of image file to convert (png|gif|jpg)') do |i|
|
12
|
+
options[:image] = i
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on('-s', '--pixel-size PIXELS', Integer, 'Size of image chunks to process into ascii (smaller => more detail)') do |s|
|
16
|
+
options[:pixel_size] = s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
option_parser.parse!
|
21
|
+
|
22
|
+
if options.empty?
|
23
|
+
puts option_parser.help
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
# required
|
28
|
+
unless options[:image] && /.*\.(png|gif|jpg)$/i =~ options[:image]
|
29
|
+
raise ArgumentError, 'Please point to an image file (png|gif|jpg)'
|
30
|
+
end
|
31
|
+
|
32
|
+
# defaults
|
33
|
+
options[:pixel_size] = 12 unless options[:pixel_size]
|
34
|
+
|
35
|
+
puts ShadedImage.new(options[:image], options[:pixel_size]).to_ascii
|
data/lib/honeybii.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
|
3
|
+
class AsciiImage
|
4
|
+
attr_accessor :raw
|
5
|
+
attr_accessor :shades
|
6
|
+
attr_accessor :ascii
|
7
|
+
|
8
|
+
def initialize(image_filename, point_size)
|
9
|
+
@raw = Magick::ImageList.new(image_filename)[0]
|
10
|
+
@point_size = point_size
|
11
|
+
@ascii = Array.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
unless @ascii.empty?
|
16
|
+
@ascii.map { |row| row.join }.join("\n")
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class ShadedImage < AsciiImage
|
2
|
+
def initialize(image_filename, point_size = 12)
|
3
|
+
super image_filename, point_size
|
4
|
+
@raw = Magick::ImageList.new(image_filename).first
|
5
|
+
@shades = ['@', '%', '8', '#', '$', 'V', 'Y', 'x', '*', '=', '+', ':', '~', '-', '.', ' ']
|
6
|
+
end
|
7
|
+
|
8
|
+
def grayscale
|
9
|
+
clone = self.clone
|
10
|
+
clone.raw = clone.raw.quantize(256, Magick::GRAYColorspace)
|
11
|
+
return clone
|
12
|
+
end
|
13
|
+
|
14
|
+
def grayscale!
|
15
|
+
@raw = @raw.quantize(256, Magick::GRAYColorspace)
|
16
|
+
end
|
17
|
+
|
18
|
+
def pixelate
|
19
|
+
columns = @raw.columns / @point_size
|
20
|
+
rows = @raw.rows / @point_size
|
21
|
+
clone = self.clone
|
22
|
+
clone.raw = clone.raw.resize_to_fit(columns, rows)
|
23
|
+
return clone
|
24
|
+
end
|
25
|
+
|
26
|
+
def pixelate!
|
27
|
+
columns = @raw.columns / @point_size
|
28
|
+
rows = @raw.rows / @point_size
|
29
|
+
@raw = @raw.resize_to_fit(columns, rows)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_ascii
|
33
|
+
clone = self.clone
|
34
|
+
clone.grayscale!
|
35
|
+
clone.pixelate!
|
36
|
+
|
37
|
+
clone.ascii = Array.new(clone.raw.rows).collect do |row|
|
38
|
+
Array.new(clone.raw.columns)
|
39
|
+
end
|
40
|
+
|
41
|
+
clone.raw.each_pixel do |pixel, col, row|
|
42
|
+
index = (((clone.shades.size - 1) * pixel.intensity).to_f / 65535.to_f).round
|
43
|
+
char = clone.shades[index]
|
44
|
+
clone.ascii[row][col] = char
|
45
|
+
end
|
46
|
+
|
47
|
+
return clone
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: honeybii
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamey DeOrio
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "<"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "<"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: A command-line image to ascii conversion tool
|
28
|
+
email: jamey@jameydeorio.com
|
29
|
+
executables:
|
30
|
+
- honeybii
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/honeybii
|
35
|
+
- lib/honeybii.rb
|
36
|
+
- lib/honeybii/ascii_image.rb
|
37
|
+
- lib/honeybii/shaded_image.rb
|
38
|
+
homepage: http://honeybii.com
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.2.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: An image to ascii converter
|
62
|
+
test_files: []
|