Image Manipulation in PHP
Image manipulation is a vital part of many web applications. PHP is able to handle most of the basic image manipulation tasks by using the GD library-short for Graphic Draw-along with a few other functions. Some examples include resizing, cropping, filtering, and compressing images. These can be time-consuming to do manually, but they can also be automated with a little programming knowledge.
The GD extension in PHP can be used to load existing images on the fly and manipulate them in various ways. It includes the imagecreatefrompng() function which can be used to create a PNG image from an existing one. The function takes a single parameter which holds the path to a png file. Alternatively, it can take a URL that will return the image resource instead.
Unlike some other GD functions that use imagecreatefromstring() to create an array of pixel values, this function returns a GdImage instance on success and false on failure. A GDImage is similar to a PHP array but with a more complex type of data.
This is the main difference between this function and others like imagecreatefromstring(). You can then pass this image to output functions like imagejpeg(), imagepng() and imagegif(). The output will either be rendered to a browser or saved as a file. Depending on the output function, you can control the quality of the final image by passing it an optional third parameter.