def __init__(self): glade = gtk.glade.XML("png-browser.glade") glade.signal_autoconnect(self) self.window = glade.get_widget("window") self.pane = glade.get_widget("pane") self.statusbar = glade.get_widget("statusbar") self.status_context_chunk = self.statusbar.get_context_id("Chunk Details") self.chunkview = glade.get_widget("chunkview") self.chunkview.append_column(gtk.TreeViewColumn("Chunk", gtk.CellRendererText(), text=0)) self.store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) self.chunkview.set_model(self.store) self.chunkview.get_selection().connect('changed', self.chunkview_selection_cb) self.current_iter = None self.current_view = None png = Png.open(file(sys.argv[1], "rb")) for c in png.chunks: i = self.store.append() self.store.set(i, 0, c.type, 1, c) self.show_chunk_page(None) self.window.show_all()
#! /usr/bin/python if __name__ == "__main__": import sys from PNG import Png png = Png.open(file(sys.argv[1], "rb")) png.write(file(sys.argv[2], "wb"))
# Do the scale thumb = pixbuf.scale_simple(target_width, target_height, gdk.INTERP_HYPER) # Now transform thumb into a valid PNG file # A little hacky, but it works. :( THUMB_FILENAME = "/tmp/temp-thumb.png" thumb.save(THUMB_FILENAME, "png") thumb = "" for line in file(THUMB_FILENAME, 'rb'): thumb = thumb + line # End of nasty evil foul hack # Insert the PNG as a sub-image into the original from PNG import Png, Chunk f = open(sys.argv[1], 'rb') png = Png.open(f) f.close() # Kill existing thumbnail [png.chunks.remove(c) for c in png.chunks if c.type == THUMBNAIL_CHUNK] # Add a new one c = Chunk(THUMBNAIL_CHUNK, thumb) # Insert this chunk at the beginning, after the IHDR and probably after the RDF. png.chunks.insert(1, c) f = file(sys.argv[1], 'wb') png.write(f) f.close()
#! /usr/bin/python if __name__ == "__main__": import sys from PNG import Png, tEXt if len(sys.argv) != 3: print "Syntax: png-get-text filename.png key" sys.exit(1) (filename, key) = sys.argv[1:] f = file(filename, 'rb') png = Png.open(f) f.close() print "\n".join([c.content for c in png.get_chunks(tEXt) if c.keyword == key])