PHP | Imagick identifyImage() Function

The Imagick::identifyImage() function is an inbuilt function in PHP which is used to identify an image and return its attributes. Attributes contain image width, height, size, and others.

Syntax:

array Imagick::identifyImage( $appendRawOutput )

Parameters: This function accepts single parameter $appendRawOutput which is used to stores the value TRUE/FALSE. If it set to TRUE then the raw output is appended to the array.



Return Value: This function returns the image attributes.

Original Image:

Below program illustrates the Imagick::identifyImage() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// require_once('path/vendor/autoload.php'); 
  
// Create an Imagick Object
$imagick = new \Imagick(
      
// Use identifyImage Function
var_dump ($imagick->identifyImage());
?>

chevron_right


Output:

array(11) { 
    ["imageName"]=> string(0) "" 
    ["mimetype"]=> string(9) "image/png" 
    ["format"]=> string(31) "PNG (Portable Network Graphics)" 
    ["units"]=> string(19) "PixelsPerCentimeter" 
    ["type"]=> string(14) "TrueColorAlpha" 
    ["colorSpace"]=> string(4) "sRGB" 
    ["compression"]=> string(3) "Zip" 
    ["fileSize"]=> string(6) "45.4KB" 
    ["geometry"]=> array(2) { ["width"]=> int(667) ["height"]=> int(184) } 
    ["resolution"]=> array(2) { ["x"]=> float(37.8) ["y"]=> float(37.8) } 
    ["signature"]=> string(64) "f64054f5bcb4cfb82c6126eff6d3d4e6be7d0e72d5620033442cecb4b9feabbd" 
}

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
$string = "Computer Science portal for Geeks!"
  
// Creating new image of above String 
// and add color and background 
$im = new Imagick(); 
$draw = new ImagickDraw(); 
  
// Fill the color in image 
$draw->setFillColor(new ImagickPixel('green')); 
  
// Set the text font size 
$draw->setFontSize(50); 
  
$metrix = $im->queryFontMetrics($draw, $string); 
$draw->annotation(0, 40, $string); 
$im->newImage($metrix['textWidth'], $metrix['textHeight'], 
new ImagickPixel('white')); 
  
// Draw the image         
$im->drawImage($draw); 
  
// identifyImage Function
var_dump ($im->identifyImage());
?> 

chevron_right


Output:

array(10) { 
    ["imageName"]=> string(0) "" 
    ["mimetype"]=> string(8) "image/x-" 
    ["units"]=> string(9) "Undefined" 
    ["type"]=> string(12) "PaletteAlpha" 
    ["colorSpace"]=> string(4) "sRGB" 
    ["compression"]=> string(9) "Undefined" 
    ["fileSize"]=> string(2) "0B" 
    ["geometry"]=> array(2) { ["width"]=> int(797) ["height"]=> int(62) } 
    ["resolution"]=> array(2) { ["x"]=> float(0) ["y"]=> float(0) } 
    ["signature"]=> string(64) "7c71a28f88b25287580277af67861eaa6f02bd5e473c88aa3bc5c046a761491d" 
}

Reference: http://php.net/manual/en/imagick.identifyimage.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.