top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the use of the function ‘imagetypes()’ in PHP?

+4 votes
935 views
What is the use of the function ‘imagetypes()’ in PHP?
posted Feb 6, 2016 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

use imagetypes() function to check which image types are supported.This function returns a bit field which returns a bit field you can use bitwise AND operator to check if a given bit is set.Constants IMG_JPG,IMG_GIF ,IMG_PNG correspond to the bit for image formats.
Example of a code segment ;

  <?php 
      $image=imagecreate(200,200);
      $white=imagecolorallocate($image,0xFF,0XFF,0XFF);
      $black=imagecolorallocate($image,0X00,0X00,0X00);
      imagefieldrectangle=($image,50,50,150,150,$black);
     if(imagetypes() &IMG_PNG)
     {
      header("Content-Type:image/png)
     imagepng($image);
     } elseif
    { 
     //same for other formats
    }
   ?>
answer Feb 6, 2016 by Shivam Kumar Pandey
0 votes

imagetypes() function to check which image types are supported.

Syntax

int imagetypes ( void )
Returns the image types supported by the current PHP installation.
Returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. 
The following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.

Example # Checking for PNG support

<?php
if (imagetypes() & IMG_PNG) {
    echo "PNG Support is enabled";
}
?>
answer Mar 11, 2016 by Ashish Kumar Khanna
...