Open In App

PHP | Imagick identifyFormat() Function

Last Updated : 08 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The Imagick::identifyFormat() function is an inbuilt function in PHP which is used to replace the embedded format characters with its appropriate image property and returns the interpreted text.

List of escape sequence: Please refer the link to see the list of escape sequence. Ref: http://www.imagemagick.org/script/escape.php

Following are the some of the important embedded formatting characters such as escape sequences for appropriate image property:

  • %h current image height in pixels
  • %i image filename (note: becomes output filename for “info:”)
  • %k CALCULATED: number of unique colors
  • %m image file format (file magic)
  • %n number of images in current image sequence
  • %w current width in pixels
  • %x x resolution (density)
  • %y y resolution (density)
  • %z image depth (as read in unless modified, image save depth)
  • %U image resolution units
  • %@ CALCULATED: trim bounding box (without actually trimming) etc…
  • Syntax:

    string Imagick::identifyFormat( $embedText )

    Parameters: This function accepts single parameter $embedText which holds a string containing formatting sequences.

    Return Value: This function returns the image format or FALSE on failure.

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

    Program: This program uses Imagick::identifyFormat() function to find the format of given Images.




    <?php
      
    // Declare new Imagick object
    $imagick = new \Imagick(
      
    // Store a string into variable
    $embedText = "Output of 'Trim box: %@ number of unique colors: %k' is: <br/>";
      
    // Use Imagick::identifyFormat() function to replace the embedded
    // format characters with its appropriate image property
    $embedText .= $imagick->identifyFormat("Trim box: %@ number of unique colors: %k");
      
    // Display the output
    echo $embedText;
      
    ?>

    
    

    Output:

    Output of 'Trim box: %@ number of unique colors: %k' is:
    Trim box: 656x144+5+15 number of unique colors: 2955

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


    Like Article
    Suggest improvement
    Previous
    Next
    Share your thoughts in the comments

    Similar Reads