Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

PHP | imagecreatefrompng() Function

  • Last Updated : 14 Feb, 2020

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




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

Output:

Program 2 (Working on loaded PNG image):




<?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);
?>

Output:

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :