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
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS