help debugging noob code - converting binary data to images...

larry at portcommodore.com larry at portcommodore.com
Mon Jun 30 05:47:01 CEST 2008


success, had to fill in a few blanks with some more googling, here is
the finished script  (used all for loops this time, saved a few more
lines):

==========

#!/usr/local/bin/python

import string
import Image, ImageDraw

size = 2

im = Image.new("1",[8*size,8*size],1)
draw = ImageDraw.Draw(im)

cset  = open("chargen","r")


for cchar in range(0, 512, 1):
    for charline in range(0, 8, 1):
        x = cset.read(1)
        ch = ord(x)
        for position in range(0, 8, 1):
            if ch & ( 2 ** position ):
                xp = (7-position)*size
                yp = charline*size
                draw.rectangle(((xp,yp),(xp+size-1,yp+size-1)),
fill=0 )
    outfile = "/home/mydir/work/char"+string.zfill(cchar,3)+".png"
    im.save(outfile,"png")
    draw.rectangle(((0,0),(size*8,size*8)),fill=1)

im.show()

==========

It does the variable sizes like I wanted and it now sure is fast.

If I wanted to display an image without saving how do I do that, on
the image module it does not pop up a canvas..  the im.show() on the
bottom does not seem to work.

Thanks again!



More information about the Python-list mailing list