Skip to content
Related Articles

Related Articles

PHP | imageresolution() Function
  • Last Updated : 19 Feb, 2020

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.

Syntax:

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 exampales illustrate the imageresolution() function in PHP:



Example 1: In this example we will get the resolution of the image.




<?php
  
// Load the png image
$image = imagecreatefrompng(
  
// Get the image resolution
$imageresolution = imageresolution($image);
print("<pre>".print_r($imageresolution, true)."</pre>");
?>

Output:

Array
(
    [0] => 96
    [1] => 96
)

Example 2: In this example we will set the resolution of the image,




<?php
  
// Load the png image
$image = imagecreatefrompng(
  
// Set the resolution
imageresolution($image, 400, 200);
  
// Get the image resolution
$imageresolution = imageresolution($image);
print("<pre>".print_r($imageresolution, true)."</pre>");
?>

Output:

Array
(
    [0] => 400
    [1] => 200
)

Reference: https://www.php.net/manual/en/function.imageresolution.php

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :