Related Articles

Related Articles

PHP | imagecreatefromgd() function
  • Last Updated : 30 Jan, 2020

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):



filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Load the GD image from localfile
$im = imagecreatefromgd('geeksforgeeks.gd');
  
// Output the image to browser
imagegd($im);
imagedestroy($im);
?>

chevron_right


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):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// As GD isn't supported in browser, it can be
// converted into PNG to be viewed in browser
// Load the GD image
$im = imagecreatefromgd('geeksforgeeks.gd');
  
// Output the image to browser
header("Content-Type: image/png");
imagepng($im);
imagedestroy($im);
?>

chevron_right


Output:

Program 3 (Converting GD into jpg):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Load the GD image
$im = imagecreatefromgd('geeksforgeeks.gd');
  
// Convert the image and save in local folder
imagejpeg($im, 'geeksforgeeks.jpg');
imagedestroy($im);
?>

chevron_right


Output:

This will convert GD image into JPEG and save in local folder.

Reference: https://www.php.net/manual/en/function.imagecreatefromgd.php




My Personal Notes arrow_drop_up
Recommended Articles
Page :