PHP | imageresolution() Function
The imageresolution() function is an inbuilt function in PHP which is used to set and return the resolution of an image in DPI (dots per inch). If none of the optional parameters is given, the current resolution is returned as an indexed array. If one of the optional parameters is given it will set both width and height to that parameter. The resolution is only used as meta information when images are read from and written to formats supporting this kind of information (currently PNG and JPEG). It does not affect how the image looks. The default resolution for new images is 96 DPI.
mixed imageresolution( resource $image, int $res_x, int $res_y )
Parameters: This function accepts three parameters as mentioned above and described below:
- $image: It specifies the image resource to work on.
- $res_x (Optional): It specifies the horizontal resolution in DPI.
- $res_y (Optional): It specifies the vertical resolution in DPI.
Return Value: This function returns the indexed array when used as getter and when used as setter returns TRUE on success or FALSE on failure.
Below examples illustrate the imageresolution() function in PHP:
Example 1: In this example we will get the resolution of the image.
Array (  => 96  => 96 )
Example 2: In this example we will set the resolution of the image,
Array (  => 400  => 200 )