Open In App

PHP | Imagick getImageProperties() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The Imagick::getImageProperties() function is an inbuilt function in PHP which is used to get the image properties.
Syntax: 
 

array Imagick::getImageProperties( string $pattern, string $includes_values )

Parameters: This function accepts two parameters as mentioned above and described below: 
 

  • $pattern: It specifies pattern for property names. Default value is * which returns all the properties.
  • $includes_values: It specifies whether to return only property names. Its default values is TRUE. If FALSE then only property names will be returned.

Return Value: This function returns an array containing the image properties or just property names.
Below programs illustrate the Imagick::getImageProperties() function in PHP:
Program 1: 
 

php




<?php
 
// Create a new imagick object
$imagick = new Imagick(
 
// Set the Image Properties
$imagick->setImageProperty('property1', 'value1');
$imagick->setImageProperty('property2', 'value2');
$imagick->setImageProperty('hello', 'world');
 
// Get the Image Profiles without values starting from "pro"
$properties = $imagick->getImageProperties("pro*", false);
print("<pre>".print_r($properties, true)."</pre>");
?>


Output: 
 

Array
(
    [0] => property1
    [1] => property2
)

Program 2: 
 

php




<?php
 
// Create a new imagick object
$imagick = new Imagick(
 
// Set the Image Properties
$imagick->setImageProperty('property1', 'value1');
$imagick->setImageProperty('property2', 'value2');
 
// Get the Image Profiles
$properties = $imagick->getImageProperties("*");
print("<pre>".print_r($properties, true)."</pre>");
?>


Output: 
 

Array
(
    [date:create] => 2019-11-21T22:32:52+05:00
    [date:modify] => 2019-11-21T22:32:52+05:00
    [png:cHRM] => chunk was found (see Chromaticity, above)
    [png:gAMMA] => gamma=0.45455 (See Gamma, above)
    [png:IHDR.bit-depth-orig] => 8
    [png:IHDR.bit_depth] => 8
    [png:IHDR.color-type-orig] => 6
    [png:IHDR.color_type] => 6 (RGBA)
    [png:IHDR.interlace_method] => 0 (Not interlaced)
    [png:IHDR.width, height] => 667, 184
    [png:pHYs] => x_res=3780, y_res=3780, units=1
    [png:sRGB] => intent=0 (Perceptual Intent)
    [png:text] => 1 tEXt/zTXt/iTXt chunks were found
    [property1] => value1
    [property2] => value2
    [Software] => Adobe ImageReady
)

Reference: https://www.php.net/manual/en/imagick.getimageproperties.php
 



Last Updated : 24 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads