Saving TGA's

t = Image.open("C:\	est.tga")
t.save ("C:\	est2.tga")

This doesn’t work, it seems like PIL can’t save out TGA’s? What is the proper way to save a TGA?

EDIT: Yikes, the Python GeSHi needs some work for the site’s scheme.

IIRC, PIL doesn’t have a tga save module :no:

In better news, the tga format’s not too complex if you want to write your own saver.

I guess the alternative is to save as bmp then run a command line conversion utility. You could even do it through Photoshop COM.

Cheers,

Drea

EDIT: On further reflection, it’s going to get ugly if you’re saving to 32bit tga.

Have you got a nice, Python friendly coder with a spare hour or two who could knock up a saver for you?

Here’s a link to the format spec.

http://www.ludorg.net/amnesia/TGA_File_Format_Spec.html

Digging a bit more.

It seems that pygame has tga load and save built in.

Works great! Saw it yesterday but didn’t have a chance to investigate.

aah thank the lord for this forum, I was just about to flip my lid! :smiley: Just spent ages making a fiddly script for organising textures and I hadn’t actually checked the tga saving, assuming it would work, silly me.

Actually, using PIL to save out tga’s appears viable if you make a slight modification to the PIL package file ImageFile.py.

In the _save function, theres a
try:
fh = fp.fileno()
fp.flush()
except AttributeError:
# code 1
else:
# code 2

When you save a tga, code 2 fires. If you modify this code so that code 1 fires instead, the tga saves out fine. Not sure about further implications or reasons for this though…