PHP Classes

Exif Capture: Extract metadata from picture files in Exif format

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 127 This week: 1All time: 9,381 This week: 571Up
Version License PHP version Categories
exifcapture 1.0.0Public Domain5PHP 5, Graphics, Files and Folders
Description 

Author

This package can Extract metadata from picture files in Exif format.

It can take the path of image file and parse it to extract details of the image like the width, height, software that was used to generate the image.

The class can extract the required details of the specified image and returns it as an associative array.

Picture of Ray Paseur
  Performance   Level  
Name: Ray Paseur is available for providing paid consulting. Contact Ray Paseur .
Classes: 8 packages by
Country: United States United States
Age: 73
All time rank: 2240311 in United States United States
Week rank: 103 Up12 in United States United States Up
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

Recommendations

extract exif data from pictures
I need the exif data from a lot off pictures

Example

<?php // demo_ExifCapture.php
/**
 * Examples using the ExifCapture class.
 */
error_reporting(E_ALL);

require_once(
'class_ExifCapture.php');
$exif_obj = new ExifCapture;
echo
'<pre>'; // MAKE THE OUTPUT EASY TO READ


// WORK WITH A SINGLE FILE
$uri = 'images/IMG_2031.JPG';


// MINIMAL DATA RETURN
$exif_data = $exif_obj->get_required_data($uri);
echo
PHP_EOL;
echo
"<b>$uri</b>" . PHP_EOL;
print_r($exif_data);
echo
PHP_EOL;


// ADD A FEW ELEMENTS TO OUR REQUIRED COLLECTION
$exif_obj->set_required_item('Height');
$exif_obj->set_required_item('Width');
$exif_obj->set_required_item('Software');


// SLIGHTLY LARGER DATA RETURN
$exif_data = $exif_obj->get_required_data($uri);
echo
PHP_EOL;
echo
"<b>$uri</b>" . PHP_EOL;
print_r($exif_data);
echo
PHP_EOL;


// CREATE AN IMAGE LIST FOR THE ENTIRE DIRECTORY
$exif_obj->get_image_list('images');

// SHOW INCLUDED AND EXCLUDED FILES
echo PHP_EOL . "<b>Here are the files we INcluded</b>" . PHP_EOL;
print_r($exif_obj->included_files);
echo
PHP_EOL;

echo
PHP_EOL . "<b>Here are the files we EXcluded</b>" . PHP_EOL;
print_r($exif_obj->excluded_files);
echo
PHP_EOL;


// PROCESS THE IMAGE LIST, SHOWING ONLY THE REQUIRED DATA
foreach ($exif_obj->included_files as $uri)
{
   
$exif_data = $exif_obj->get_required_data($uri);
    echo
PHP_EOL;
    echo
"<b>$uri</b>" . PHP_EOL;
   
print_r($exif_data);
    echo
PHP_EOL;
}

// PROCESS THE DIRECTORY, SHOWING ALL THE INFORMATION WE GOT
foreach ($exif_obj->included_files as $uri)
{
   
$exif_data = $exif_obj->get_image_data($uri);
    echo
PHP_EOL;
    echo
"<b>$uri</b>" . PHP_EOL;
   
print_r($exif_data);
    echo
PHP_EOL;
}

// GATHER EVERYTHING PHP KNOWS ABOUT EXIF AND SHOW THE OBJECT PROPERTIES (LARGE OUTPUT)
$exif_obj->build_exif_array();
print_r($exif_obj);


Details

Class ExifCapture This class uses the PHP Exif extension to extract metadata from image files. Although PHP can recognize many kinds of image files, the Exif extension only seems to work well with JPG and TIF files. The Class was motivated by this need: https://www.phpclasses.org/recommend/1119-I-need-the-exif-data-from-a-lot-off-pictures.html References: https://sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html http://exif.org/Exif2-2.PDF http://php.net/manual/en/ref.exif.php http://php.net/manual/en/exif.requirements.php Exif has a lot of "loose ends" shown here https://stackoverflow.com/questions/5184748/php-bad-exif-data-warnings-what-to-do https://bugs.php.net/bug.php?id=72819 Exif data comes in multidimensional arrays. Which arrays are present in any given image? Who knows! Consult the "SectionsFound" element. In my experimentation the most useful information was contained in FILE, COMPUTED, IFD0, and EXIF arrays. Within these arrays the items are given easy-to-understand names like "FileName" and "MimeType." BTW, It's IFD zero, not IFD oh. The Class provides the following methods __construct() makes opinionated assumptions about what information will be captured, and what unuseful information will be discarded. You may want to modify these underlying assumptions. set_included_array() can be used to capture other sections of the Exif. set_required_item() can be used to limit the return to certain items. set_excluded_item() can be used to remove items from the collection. get_image_data() returns as much data as possible for a given image file, subject to the constraints of the included arrays and the excluded items. This can be quite a lot of information. get_required_data() returns only the information that has been explicitly requested by the constructor and set_required_item(). get_image_list() creates class properties that segregate files with Exif information from files that do not provide PHP-readable Exif. The properties are arrays that can be iterated with foreach(). build_exif_array() finds all of the Exif values that PHP knows about. Many (perhaps most) of these are not going to be present in your image file. Call this method, then print the object to see them. Some image files will have more Exif than others. After processing with Photoshop, some image files gain additional Exif. Some image editors can strip Exif, which may make the image file smaller so that it loads faster over the internet. Please see the demo file for examples that use the methods.

Screenshots  
  • screenshot.png
  Files folder image Files  
File Role Description
Plain text file class_ExifCapture.php Class Class Source
Accessible without login Plain text file demo_ExifCapture.php Example Demonstration
Accessible without login Plain text file readme_ExifCapture.txt Doc. Readme

 Version Control Unique User Downloads Download Rankings  
 0%
Total:127
This week:1
All time:9,381
This week:571Up