Tuesday, November 19, 2024
Google search engine
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 Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments