Sha256: d3701d7b8353215066a9208e610450af27e58027ee4faefac8f135ee3b3531ba

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

Contents

#!/usr/bin/env ruby
require 'zpng'

class ChunkAppender
  def initialize image
    @image = image.is_a?(ZPNG::Image) ? image : ZPNG::Image.load(image)
  end

  def list_chunks
    @image.chunks.each_with_index do |c, idx|
      printf "%3d: type=%4s size=%d\n", idx, c.type, c.size
    end
  end

  def append chunk_no, data
    @image.chunks[chunk_no].define_singleton_method :export_data do
      super() + data
    end
    self
  end

  def save fname
    @image.save(fname, :repack => false)
  end
end

if $0 == __FILE__
  case ARGV.size
  when 1
    ChunkAppender.new(ARGV[0]).list_chunks
  when 3,4
    fname, chunk_no, data, oname = ARGV
    oname ||= fname.chomp(File.extname(fname)) + ".out" + File.extname(fname)
    ChunkAppender.new(fname).
      append(chunk_no.to_i, data).
      save(oname)
    puts "[=] #{oname} saved"
  else
    bname = File.basename($0)
    puts "USAGE:"
    puts "  Append data to specified chunk:"
    puts "    #{bname} input.png <chunk_no> <data> [output.png]"
    puts
    puts "  List chunks:"
    puts "    #{bname} input.png"
    exit
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
zsteg-0.2.13 writers/chunk_append.rb
zsteg-0.2.12 writers/chunk_append.rb
zsteg-0.2.11 writers/chunk_append.rb
zsteg-0.2.10 writers/chunk_append.rb
zsteg-0.2.9 writers/chunk_append.rb
zsteg-0.2.8 writers/chunk_append.rb
zsteg-0.2.7 writers/chunk_append.rb
zsteg-0.2.6 writers/chunk_append.rb
zsteg-0.2.5 writers/chunk_append.rb
zsteg-0.2.4 writers/chunk_append.rb
zsteg-0.2.3 writers/chunk_append.rb
zsteg-0.2.2 writers/chunk_append.rb
zsteg-0.2.1 writers/chunk_append.rb
zsteg-0.2.0 writers/chunk_append.rb
zsteg-0.1.2 writers/chunk_append.rb
zsteg-0.1.1 writers/chunk_append.rb
zsteg-0.1.0 writers/chunk_append.rb