#!/usr/bin/env python

FILENAME = "/usr/share/blogfish/blue-angelfish.png"

import os
import gtk
from struct import *
import imghdr

pb = gtk.gdk.pixbuf_new_from_file(FILENAME)
pix = pb.get_pixels()

print "ht %s" % pb.get_height()
print "wi %s" % pb.get_width()
print "rs %s" % pb.get_rowstride()
print "bps %s" % pb.get_bits_per_sample()
print "len pix %s " % len(pix)
	
f = file("foo.bmp", "w")

# header
size = (len(pix)/4) + 14 + 40 
offset = 14 + 40
bmph = "BM" + pack("I 2H I", size, 0, 0, offset)
bmph = bmph + pack("I 2i H H I I 2i I I", 54, pb.get_width(), pb.get_height(), \
	1, 32, 0, len(pix), 1000, 1000, \
	0,0)

f.write(bmph)
f.write(pb.get_pixels())
f.close()
print imghdr.what("foo.bmp")
os.system("display foo.bmp")
pb2 = gtk.gdk.pixbuf_new_from_file("foo.bmp")
