 | Expert | | Join Date: Jul 2006 Location: Norway
Posts: 113
# 1
Aug 11 '09
| |
First, PIL is a great library, however, sometimes I do perhaps not work on my own computer, but rather some obscure computer with an old version of python, with an unknown unix/linux that I have to telnet to. However, I still might want to create some images for instance for no particular reason make a display hack
Below is a packed together routine, that creates an TGA image from an pixmap (i.e. a list that defines a bitmap) with an example how-to use -
def writetga(width,height,data,filename):
-
f = open(filename,"wb")
-
f.write("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c" % (0,0,2,0,0,0,0,0,0,0,0,0,(width & 0x00ff)%0xff,(width & 0xff00)%0xff,(height & 0x00ff)%0xff,(height & 0xff00)%0xff,0x18,0x0))
-
for i in range(height-1):
-
for j in range(width-1):
-
f.write("%c%c%c" % (data[j+i*(width-1)][0],data[j+i*(width-1)][1],data[j+i*(width-1)][2]))
-
f.close()
-
-
pixmap = []
-
for i in range(256):
-
for j in range(256):
-
pixmap.append([(i^j)%256,(i^j)%256,(i^j)%256])
-
-
writetga(256,256,pixmap,"test1.tga")
-
-kudos
|