PHP | imagecreatefrompng() Function

The imagecreatefrompng() function is an inbuilt function in PHP which is used to create a new image from PNG file or URL. This image can be further worked upon in the program. This function is usually used when you want to edit your PNG images.

Syntax:

resource imagecreatefrompng( string $filename )

Parameters: This function accepts a single parameter $filename which holds the name of image.

Return Value: This function returns an image resource identifier on success, FALSE on errors.

Below given programs illustrate the imagecreatefrompng() function in PHP:



Program 1 (Viewing the loaded PNG image):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Load an image from PNG URL
$im = imagecreatefrompng(
  
// View the loaded image in browser
header('Content-type: image/png');  
imagepng($im);
imagedestroy($im);
?>

chevron_right


Output:

Program 2 (Working on loaded PNG image):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Load an image from PNG URL
$im = imagecreatefrompng(
  
// Flip the image
imageflip($im, 2);
  
// View the loaded image in browser
header('Content-type: image/png');  
imagepng($im);
imagedestroy($im);
?>

chevron_right


Output:

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

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.