imagecreatefromtga 


gd apg

CREATE a new image from file or URL from a TGA image.


This function is available as of PHP 7.4.0.





This function returns an image identifier representing the image obtained from the given filename.





This function returns FALSE on errors.

The GdImage, resource or object returned by this function allows the creation of other image formats from TGA format.





 TGA format 


TGA refers to a raster graphics file format created by Truevision Inc.

This format had been used as the native format for TARGA and VISTA graphic cards for IBM PC’s to support Truecolor display.

TGA files are common in animation and video industry.

This format is not suitable for photographic images but works fine for simpler images like icons, cartoons and line drawings.

With TGA format Image data can be stored as raw, or a lossless RLE compression can be used.

TGA files can be opened with Adobe Photoshop, GIMP, Paint.NET, Corel PaintShop Pro, TGA Viewer, and probably some other popular photo and graphics tools as well.

TGA also stands for various things that have nothing to do with the TARGA file format.

For example, The Gaming Armageddon and Tandy Graphics Adapter both use the TGA abbreviation.

The latter, however, is related to computer systems but not to this image format; it was a display standard for IBM video adapters that could display up to 16 colors.



<?php

GdImage
|false imagecreatefromtgastring $filename )


where,

$filename The path to an existing TGA image 

?>
 

  $filename   


The path or stream resource.

$filename can reference a local file or, (configuration permitting), a remote file using one of the supported stream wrappers:

STREAM WRAPPERS MEANING
file:// LOCAL File System
http:// URL HTTP
ftp:// URL FTP
php:// I/O streams
zlib:// Data Compression stream
data:// DATA (RFC-2397)
glob:// Find Filenames
phar:// PHP Archive
ssh2:// Secure Shell 2
rar:// RAR
ogg:// Audio
expect:// Interaction of stream processes
ed48


  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

if (!
extension_loaded('gd')) 
die(
'skip extension gd required');
if (!(
imagetypes() & IMG_TGA)) 
die(
'skip TGA support required');

$img_file "tga/TGA 001 01 Belém.tga";

echo 
$img_file?><br><br>Existing Image...<br>
However, it cannot be displayed by this browser.

<?php

$im01 
imagecreatefromtga($img_file);

// var_dump($im01);

echo '<br><br>';

$img_name "jpeg/JPEG 014 01 Belém (tga2jpeg).jpg";

$bool01 imagejpeg($im01$img_name);

if (
$bool01 == true)  
{  
echo 
'<br>The new format has been created!<br><br>' 
$img_name '<br><br>';  

echo 
'<img src="' $img_name 
'" alt="' $img_name '" title="' $img_name '" width="400">';
}  
else  
{  
echo 
'$bool01 = ' $bool01 
'<br><br>The image was NOT created!';  
}  

?> 

 RESULT   

TGA 001 01 Belém.tga

Existing Image
However, it cannot be displayed by this browser.



The new format of the image has been created!


JPEG 014 01 Belém (tga2jpeg).jpg

JPEG 014 01 Belém (tga2jpeg).jpg apr