class Dimscan::PNGScanner
Scans dimensions from a PNG image
Constants
- IHDR
Protected Instance Methods
extract_dimensions(bytes)
click to toggle source
# File lib/dimscan/png_scanner.rb, line 24 def extract_dimensions(bytes) byte_string = bytes.map(&:chr).join byte_string.unpack('NN') end
scan(bytes) { |first.chr| ... }
click to toggle source
# File lib/dimscan/png_scanner.rb, line 10 def scan(bytes) # Dimensions are in 8 bytes after IHDR last_slice = nil bytes.each_cons(IHDR.size + 8) do |slice| yield slice.first.chr last_slice = slice if slice.first(IHDR.size) == IHDR return extract_dimensions(slice.last(8)) end end yield last_slice[1..-1].map(&:chr).join nil end