access tga image size

Larry Bates lbates at swamisoft.com
Mon Sep 13 17:44:49 EDT 2004


You will need to get and install a copy of
PIL (Python Imaging Library) available at:

http://www.pythonware.com/products/pil/index.htm

then in Python:

import Image

filepath='<insert filename path here>'
im=Image.open(filepath)
height, width=im.size
print "%s-height=%i, width=%i" % (filepath, height,
                                  width)

or for all files in a directory

import glob
import Image

filepathlist=glob.glob(r"c:\images\*.tga")
for filepath in filepathlist:
    im=Image.open(filepath)
    height, width=im.size
    print "%s-height=%i, width=%i" % (filepath, height,
                                  width)


Larry Bates
Syscon, Inc.


"haddock" <saperlipopette at gmx.ch> wrote in message
news:8c2f23c.0409131332.41657a38 at posting.google.com...
> hi all
>
> Is it possible to access the size (with and height) of a .tga image in
> python? From the documentation I would say no, but I'm pretty new to
> python...
>
> if the answer really is no, has someone a suggestion how else I could
> write a little script that computes the total area of a large nuber of
> image files in a folder? I should check texturespace for 3D Models,
> and would like to avoid copy pasting them all into Photoshop...
>
> thanks for your trouble
>
> haddock





More information about the Python-list mailing list