PHP | imagecreatefromgd() function
The imagecreatefromgd() function is an inbuilt function in PHP which is used to create a new image from GD file or URL. Further, this image can be worked upon in the program. An image can be converted into GD format using the imagegd() function.
Syntax:
resource imagecreatefromgd( string $filename )
Parameters:This function accepts a single parameter $filename which holds the name or URL of file.
Return Value: This function returns an image resource identifier on success, FALSE on errors.
Below given programs illustrate the imagecreatefromgd() function in PHP:
Program 1 (Viewing a gd file in browser):
<?php
$im = imagecreatefromgd( 'geeksforgeeks.gd' );
imagegd( $im );
imagedestroy( $im );
?>
|
Output:
This will load gd image in text form as it is not supported by browser.
Program 2 (Converting GD into png and viewing in browser):
<?php
$im = imagecreatefromgd( 'geeksforgeeks.gd' );
header( "Content-Type: image/png" );
imagepng( $im );
imagedestroy( $im );
?>
|
Output:
Program 3 (Converting GD into jpg):
<?php
$im = imagecreatefromgd( 'geeksforgeeks.gd' );
imagejpeg( $im , 'geeksforgeeks.jpg' );
imagedestroy( $im );
?>
|
Output:
This will convert GD image into JPEG and save in local folder.
Reference: https://www.php.net/manual/en/function.imagecreatefromgd.php
Last Updated :
30 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...