lib/zpng/cli.rb in zpng-0.2.2 vs lib/zpng/cli.rb in zpng-0.2.3

- old
+ new

@@ -132,11 +132,11 @@ @img.crop! :width => $1.to_i, :height => $2.to_i, :x => $3.to_i, :y => $4.to_i print @img.export unless @actions.include?(:ascii) end def load_file fname - @img = Image.load fname, :verbose => true + @img = Image.load fname, :verbose => @options[:verbose]+1 end def metadata return if @img.metadata.empty? puts "[.] metadata:" @@ -189,13 +189,18 @@ puts end end def chunks idx=nil + max_type_len = 0 + unless idx + max_type_len = @img.chunks.map{ |x| x.type.to_s.size }.max + end + @img.chunks.each do |chunk| next if idx && chunk.idx != idx - colored_type = chunk.type.magenta + colored_type = chunk.type.ljust(max_type_len).magenta colored_crc = if chunk.crc == :no_crc # hack for BMP chunks (they have no CRC) '' elsif chunk.crc_ok? 'CRC OK'.green @@ -257,11 +262,17 @@ end def palette if @img.palette pp @img.palette - hexdump(@img.palette.data, :width => 3, :show_offset => false) do |row, offset| - row.insert(0," color %4s: " % "##{(offset/3)}") + if @img.format == :bmp + hexdump(@img.palette.data, :width => 4, :show_offset => false) do |row, offset| + row.insert(0," color %4s: " % "##{(offset/4)}") + end + else + hexdump(@img.palette.data, :width => 3, :show_offset => false) do |row, offset| + row.insert(0," color %4s: " % "##{(offset/3)}") + end end end end def colors