Thursday, September 4, 2025
HomeLanguagesPHP | imagecreatefrompng() Function

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




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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6715 POSTS0 COMMENTS