The imagepng() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to PNG and applying filters to the image.
bool imagepng( resource $image, int $to, int $quality, int $filters)
Parameters: This function accepts three parameters as mentioned above and described below:
- $image: It specifies the image resource to work on.
- $to (Optional): It specifies the path to save the file to.
- $quality (Optional): It specifies the quality of the image.
- $filters (Optional): It specifies the filters to apply to the image which help in reducing the image size.
Return Value: This function returns TRUE on success or FALSE on error.
Below examples illustrate the imagepng() function in PHP:
Example 1: In this example we will be viewing an image in browser.
Example 2: IN this example we will convert JPEG into PNG.
This will save the PNG version of image in the same folder where your PHP script is.
Program 3: In thi example we will use filters.
This will save the image1.png as compressed and image2.png as uncompressed image
- How to get the function name inside a function in PHP ?
- p5.js | abs() function
- p5.js | sq() function
- p5.js | pow() function
- PHP | ord() Function
- p5.js | int() function
- p5.js | str() function
- CSS | url() Function
- CSS | var() Function
- p5.js | arc() Function
- p5.js | log() function
- p5.js | hue() function
- CSS | hsl() Function
- p5.js | red() function
- p5.js | min() function
- p5.js | cos() function
- PHP | each() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.