ansify 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +19 -10
  2. data/ansify.gemspec +5 -1
  3. data/bin/ansify +30 -24
  4. 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 PNG images to ANSI escape codes.
4
+ A command-line tool to convert images to ANSI escape codes.
5
5
 
6
6
  Installation
7
7
  ------------
8
8
 
9
- sudo gem install ansify
9
+ gem install ansify
10
10
 
11
11
  Usage
12
12
  -----
13
13
 
14
14
  > ansify --help
15
- ansify v0.0.1
15
+ ansify v0.0.2
16
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
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
- Todo
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
+ ![ansi](https://github.com/enricruiz/ansify/raw/master/examples/output.png)
25
36
 
26
- * Add file output
27
- * Handle resampling to higher resolution
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ansify'
3
- s.version = '0.0.1'
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 'chunky_png'
3
+ require 'RMagick'
4
4
  require 'rainbow'
5
5
  require 'trollop'
6
6
 
7
- VERSION = "0.0.1"
7
+ VERSION = "0.0.2"
8
8
 
9
9
  options = Trollop::options do
10
10
  version "ansify v#{VERSION}"
11
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"
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
- 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]
18
+ image = Magick::Image.read(options[:image]).first
19
19
 
20
- image = ChunkyPNG::Image.from_file(options[:file])
20
+ width = image.columns
21
+ height = image.rows
21
22
 
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)
23
+ if options[:scale]
24
+ if options[:sampling]
25
+ image = image.sample(options[:scale])
28
26
  elsif
29
- image = image.resample_bilinear(w, h)
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..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
+ (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
- print a > 128 ? " ".background(r, g, b) : " "
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.1
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: