Skip to main content

Working with Image Metadata in PHP

Sometimes you want to extract the descriptive information embedded in an image, such as the metadata or thumbnails placed in digital photos. For this, you can use PHP’s Exchangeable Image File Format (EXIF) functions. EXIF is a standard for storing descriptive metadata in image files, particularly JPEG and TIFF files.

PHP’s exif_read_data() function can read these headers and extract the information stored within them. below is an example code which extract the information embed in an image.

  1. <?php
  2. $DIR = “C:/Users/laeeq/Pictures/”;
  3. $filelist = glob(“$DIR/*.jpg”);
  4. if(sizeof($filelist)>0) {
  5. foreach($filelist as $file) {
  6. $exif = exif_read_data($file, 0, true);
  7. echo “File: $file \n”;
  8. foreach($exif as $section => $data) {
  9. foreach($data as $key => $value) {
  10. echo “$section -> $key = $value \n”;
  11. }
  12. }
  13. echo “\n”;
  14. }
  15. }
  16. ?>

PHPZAG.COM is a popular PHP tutorial blog that publishes useful tips and tutorials for PHP programmer. If you would like to be kept up to date with our posts, you can subscribe to our RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *


Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!