a few words about web development

TGA: imagetga + imagecreatefromtga

Another straight to the point solution
A few years ago I wrote a library to handle TGA format with PHP. It got quite popular amongst PHP programmers and was included in a few interesting PHP projects, for example WideImage by Gasper Kozak. So here's an updated code. It supports more TGA subformats (not just 24 bit images) and makes it possible to create TGA images with PHP.

Installation


Just download the zip below and unpack wherever you want it. It should work fine with any PHP version from 5 up.

License: MIT


Features


Loading TGA images:
  • 8bpp grayscale
  • 24bpp truecolor
  • 32bpp truecolor (RGBA)
  • normal and upside-down
  • RLE compressed and uncompressed
Saving TGA images:
  • 32bpp truecolor (RGBA)
Does not work with palette-based images (type 1 and 9).

Usage examples


Loading TGA image and saving as PNG:
$im = imagecreatefromtga('image.tga');
imagepng($im, 'output.png');

Loading PNG and saving as TGA:
$im = imagecreatefrompng('image.png');
imagetga($im, 'output.tga');

Getting image's width and height without loading & parsing the whole image:
list($width, $height, $type, $bits, $type) = getimagesizetga('image.tga');
echo 'Width: ' . $width . ' Height: '. $height;

Comments

NewEXEThank you very much!