

Likewise, PNG files have the string PNG fairly near the start (it's not quite at the very begining again, you'd need to research the file format specifics to help you determine how much you'd need to know to be certain). (it could still be a text file though, that just happens to start with 'GIF89a' you'd have to parse more of the file to be absolutely certain) If you can find that string at the begining of the file, you can be reasonably sure that it is a GIF image and absolutely certain it isn't any other image format. Īnd, let us experiment with different images captured by different devices, to see the differences between the resultant property array will be returned.If you know a minimal amount about the file format structure, you could theoretically look at the top bytes of the file until you could work out what type of file it is.įor example, a GIF image always starts with the following bytes GIF89a. In the above program, replace the line which invokes getimagesize() function, that is, īy the following line for getting image properties in EXIF format. Not only the type of the images but also the entire list of image properties returned by this function, will also be varied depends on devices. For example, if image type returned as 2 denotes that, it is JPEG image. Image types are returned as numbers that are associated with the available types of images like gif, png and etc. Image types are of 16 totally, which varies based on the devices used to capture images. Exif is a standard format, that can be expanded as Exchangeable Image Format. This function will be used to extract properties of digital images in which Exif data is stored in its header. So, added to the width, height information, it will return a huge list of additional information such as image created date, last modified date, File name, size, orientation, resolution and etc. Since getimagesize() functions will return limited set of properties, exif_read_data() is used to get more information further associated with images. After ensuring that the $_FILES is not empty, then, we should specify the name of the file to getimagesize() as shown above.įinally, image properties are returned as an array and displayed to the browser, in human readable format, by using PHP print statement inside pre tags. This script will be executed on submitting the form, and the image file is added to PHP global array, that is, $_FILES. Īfter that, we need to access these from data from a PHP script to be embedded on top of the above content. But this attribute can be used, if the form method is posted, as like as the following content. As we have seen, to upload files through HTML form, we need to specify the enctype attribute to the form. For that, we need to access HTML form data on submitting the selected image file.įirst, create HTML content to select the image file for which we need to extract properties. The following PHP program is used to extract the properties of an image. Rather, we should specify the path of the image file, which can be either relative or absolute path.


But, there is no need to send resource data of the image as the argument of this function. This method will return a limited amount of image data. This PHP method that returns an array of image properties like width, height, image type, mime type and etc. If we want to check the width and height of the captcha we have created, then, imagesx() and imagesy() could be used appropriately.
#PHP IMAGETYPE CODE#
For that, it accepts the resource type of data which will be returned on creating new images dynamically using PHP script.įor example, PHP captcha code is created dynamically as images to ensure that the input of web application is entered by the human. The imagesx() and imagesy() are used to extract the width and height of the images respectively. And the order should be as shown above to enable mbstring before exif. For that, we should search for these all names among php.ini, and could be found as, extension=php_mbstring.dllĪnd then, enable this DLL by removing semicolon( ) at the beginning of each line. The corresponding DLL to be enabled for using these functions are php_mbstring.dll, php_exif.dll. PHP provides various functions and DLL to extract image properties from an image.
#PHP IMAGETYPE HOW TO#
In this article, we have to see how to get metadata of images using PHP script. This information are not obvious to the user on simply viewing the images. For example, image type, image width, and height, attributes, created date, last modified date and etc. The data or Information that are associated with an image is called as metadata of the images.
