a few words about web development

Open TGA with PHP: imagecreatefromtga

Another straight to the point solution
Need to read TGA files in PHP? Here's an implementation of imagecreatefromtga, which reads 24 bit TGA images both RLE compressed and uncompressed as these are the most popular variants of TGA files. If you need support for any other variant of TGA (like RLE compressed 32 bpp image)- leave a comment and perhaps one day I will find a minute to implement support of it.

You can use it as any other imagecreatefrom* function:

include 'tga.php';
//convert TGA to PNG
$im = imagecreatefromtga('test.tga');
imagepng($im, 'test.png');

You can also read small fraction of TGA file to get its width, height, number of bits per pixel and also check if this is a proper TGA file (inproper TGA will return zeroes):

list($width, $height, $type, $bits, $tga_type) = getimagesizetga('test1.tga');
echo 'Width: ' . $width . ' Height: '. $height;

Comments