Connecting Tech Pros Worldwide Forums | Help | Site Map

Doing bitmap things without python imaging library (PIL)

kudos's Avatar
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

Expand|Select|Wrap|Line Numbers
  1. def writetga(width,height,data,filename):
  2.  f = open(filename,"wb")
  3.  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))
  4.  for i in range(height-1):
  5.   for j in range(width-1):
  6.    f.write("%c%c%c" % (data[j+i*(width-1)][0],data[j+i*(width-1)][1],data[j+i*(width-1)][2]))
  7.  f.close()
  8.  
  9. pixmap = []
  10. for i in range(256):
  11.  for j in range(256):
  12.   pixmap.append([(i^j)%256,(i^j)%256,(i^j)%256])
  13.  
  14. writetga(256,256,pixmap,"test1.tga")
  15.  
-kudos



Reply