PHP | Imagick identifyFormat() Function

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.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?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;
      
    ?>

    chevron_right

    
    

    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



    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.




    Article Tags :
    Practice Tags :


    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.