imagecreatefrompng 


gd apg

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





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 PNG format.



<?php

GdImage
|false imagecreatefrompngstring $filename )


where,

$filename The path to an existing PNG 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>';

$img_file "png/PNG 006 01.png";

echo 
$img_file?><br><br>Existing Image
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="P N G">

<?php

$im01 
imagecreatefrompng($img_file);

echo 
'<br><br>resource or object for the 
            future image to be created by this function.<br><br>'
;
            
var_dump$im01 );

?> 

 RESULT   

PNG 006 01.png

Existing Image

PNG 01 imagestring.png apr

The identifier for the created image:

resource(6) of type (gd)
or
object(GdImage)#1 (0) { }


  2 EXERCISE   

<?php

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

$img_file "png/PNG 019 02 (gif2png).png";

$img_name "jpeg/JPEG 009 02 (png2jpeg).jpg"

echo 
$img_file?><br><br>Existing Image 
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="P N G"> 

<?php

$im02 
imagecreatefrompng($img_file); 

echo 
'<br><br>The identifier to be used:<br><br>';
var_dump($im02); 

$bool02 imagejpeg($im02$img_name);   

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

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

?> 

 RESULT   

PNG 019 02 (gif2png).png

Existing Image

PNG 019 02 (gif2png).png apr

The identifier to be used:

resource(6) of type (gd)
or
object(GdImage)#1 (0) { }

The new format has been created!

JPEG 009 02 (png2jpeg).jpg

JPEG 009 02 (png2jpeg).jpg apr


  3 EXERCISE   

<?php

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

$img_file "png/PNG 006 01.png";

$img_name "gd/GD 004 03 (png2gd).gd"

echo 
$img_file?><br><br>Existing Image 
<br><br><img src="<?php echo $img_file?>
alt="<?php echo $img_file?>" title="P N G"> 

<?php

$im03 
imagecreatefrompng($img_file); 

echo 
'<br><br>The identifier to be used:<br><br>';
var_dump($im03); 

$bool03 imagegd($im03$img_name);   

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

echo 
'<br><br>However, it cannot be 
                displayed by this browser.'

}   
else   
{   
echo 
'$bool03 = ' $bool03 
               
'<br><br>The image was NOT created!';   
}   

?>

 RESULT   

PNG 006 01.png

Existing Image

PNG 006 01.png apr

The identifier to be used:

resource(7) of type (gd)
or
object(GdImage)#1 (0) { }

The new format of the image has been created!

GD 004 03 (png2gd).gd

However, it cannot be displayed by this browser.