imageparser 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.
Files changed (2) hide show
  1. data/lib/imageparser.rb +28 -0
  2. metadata +46 -0
@@ -0,0 +1,28 @@
1
+ # Image Parser
2
+ # Supports PPM and PTF file formats.
3
+ class ImageParser
4
+ attr_accessor :con
5
+ def initialize(file=nil)
6
+ @con = File.read(file, mode: 'rb') if file
7
+ end
8
+
9
+ # Parse a PPM file.
10
+ # Add parsed results into the hash `info`.
11
+ # These results are, the header, the width, the height, the RGB max value, the raster and the raster grid.
12
+ def parse_ppm(info)
13
+ info[:header] = @con.split(" ")[0] if @con.split(" ")[0] == "P6"
14
+ info[:width] = @con.split(" ")[1].to_i if @con.split(" ")[1].to_i > 0
15
+ info[:height] = @con.split(" ")[2].to_i if @con.split(" ")[2].to_i > 0
16
+ info[:rgb] = @con.split(" ")[3].to_i if @con.split(" ")[3].to_i > 0 && @con.split(" ")[3].to_i < 65536
17
+ info[:raster] = @con.split(" ")[4..-1][0].unpack("C*")
18
+ info[:raster_grid] = info[:raster].each_slice(info[:width] * 3).to_a
19
+ end
20
+
21
+ # Parse a PTF file.
22
+ # Add parsed results into hash `info`.
23
+ # These results are, the header and the color information.
24
+ def parse_ptf(info)
25
+ info[:header] = @con.split(" ")[0] if @con.split(" ")[0] == "PTF1"
26
+ info[:color_info] = @con.split(",")[1..-1].map {|s| s.delete ' '}
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imageparser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Himpon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-03-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Image Parsing Gem
15
+ email: synattack@hotmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/imageparser.rb
21
+ homepage: http://rubygems.org/gems/imageparser
22
+ licenses:
23
+ - GPLv2
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.23
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Image Parsing
46
+ test_files: []