Use EXIF function set in PHP to display EXIF information of SLR photos

Source: Internet
Author: User
Use EXIF function set to display EXIF information of SLR photos in PHP

To be able to successfully use the EXIF function to display the SLR EXIF information needs a few steps:

1. Modify EXIF information for php.ini

2. Continue to modify the php.ini information, find the following module, will be with the Exif configuration attributes before; remove, and then restart Apache

3. Verify that PHP does open the EXIF module successfully, using the following code

Echo Phpinfo ();
?>
If you see the display, the Exif module is successfully opened so that we can start using its set of functions

4. Start writing related classes (or functions, which are encapsulated by others, I personally think this is appropriate), as below, you can modify their own code for their own use

function Getimageinfoval ($ImageInfo, $val _arr) {
$InfoVal = "Unknown";
foreach ($val _arr as $name = + $val) {
if ($name = = $ImageInfo) {
$InfoVal = & $val;
Break
}
}
return $InfoVal;
}
function Getimageinfo ($img) {
$imgtype = Array ("", "GIF", "JPG", "PNG", "SWF", "PSD", "BMP", "TIFF (Intel byte Order)", "TIFF (Motorola byte order)", "JPC "," JP2 "," JPX "," JB2 "," SWC "," IFF "," WBMP "," XBM ");
$Orientation = Array ("", "top left Side", "top right side", "bottom right side", "bottom left side", "left side top", "rig HT side Top "," right Side Bottom "," left Side Bottom ");
$ResolutionUnit = Array ("", "" "," "", "" cm ");
$YCbCrPositioning = Array ("", "the center of Pixel Array", "The Datum point");
$ExposureProgram = Array ("Undefined", "manual", "Standard program", "Aperture precedent", "shutter precedent", "depth of field", "Sport Mode", "Portrait Mode", "landscape mode");
$MeteringMode _arr = Array (
"0" = "Unknown",
"1" = "average",
"2" = "Central weighted average metering",
"3" + "point test",
"4" = "Partition",
"5" = "Evaluation",
"6" = "local",
"255" = "Other"
);
$Lightsource _arr = Array (
"0" = "Unknown",
"1" = "Daylight",
"2" = "fluorescent",
"3" = "tungsten filament",
"Ten" = "flash",
"+" = "standard Light a",
"+" = "Standard light B",
"+" = "standard light C",
"A" and "D55",
"+" = "D65",
"A" and "D75",
"255" = "Other"
);
$Flash _arr = Array (
"0" = "flash did not Fire",
"1" = "flash fired",
"5" = "Flash fired but strobe return light not detected",
"7" = "Flash fired and strobe return light detected",
);

$exif = Exif_read_data ($img, "IFD0");
if ($exif ===false) {
$new _img_info = Array ("File Information" = "No Picture exif information");
}
Else
{
$exif = Exif_read_data ($img, 0,true);
$new _img_info = Array (
"File Information" = "-----------------------------",
"File name" = $exif [File][filename],
"file Type" = = $imgtype [$exif [File][filetype]],
"File Format" = $exif [File][mimetype],
"File Size" = $exif [File][filesize],
"Timestamp" = Date ("y-m-d h:i:s", $exif [File][filedatetime]),
"Image Information" = "-----------------------------",
"Picture description" and "$exif [Ifd0][imagedescription],
"Manufacturer" = $exif [Ifd0][make],
"Model" = $exif [Ifd0][model],
"Direction" = $Orientation [$exif [ifd0][orientation]],
"Horizontal Resolution" = $exif [ifd0][xresolution]. $ResolutionUnit [$exif [Ifd0][resolutionunit]],
"Vertical Resolution" = $exif [ifd0][yresolution]. $ResolutionUnit [$exif [Ifd0][resolutionunit]],
"Create software" = $exif [Ifd0][software],
"Modified Time" = $exif [Ifd0][datetime],
"Author" = $exif [Ifd0][artist],
"YCbCr position Control" = $YCbCrPositioning [$exif [ifd0][ycbcrpositioning]],
"Copyright" = $exif [Ifd0][copyright],
"Photography Copyright" = $exif [Computed][copyright.photographer],
"Edit Copyright"-$exif [Computed][copyright.editor],
"Shooting Information" = "-----------------------------",
"EXIF Version" = $exif [Exif][exifversion],
"FlashPix Version" = "Ver.". Number_format ($exif [exif][flashpixversion]/100,2),
"Shooting Time" = $exif [exif][datetimeoriginal],
"Digital Time" = $exif [exif][datetimedigitized],
"Shooting resolution High" = $exif [Computed][height],
"Shooting resolution width" = $exif [Computed][width],
/*
The actual aperture value of lens when the image is taken.
Unit is APEX.
To convert this value to ordinary f-number (f-stop),
Calculate this value ' s power of Root 2 (=1.4142).
For example, if the Aperturevalue are ' 5 ', f-number is pow (1.41425,5) = F5.6.
*/
"Aperture" = $exif [Exif][aperturevalue],
"Shutter Speed" = $exif [Exif][shutterspeedvalue],
"Shutter Aperture" = $exif [Computed][aperturefnumber],
"Maximum aperture value" = "F". $exif [Exif][maxaperturevalue],
"Exposure Time" = $exif [Exif][exposuretime],
"F-Number" = $exif [Exif][fnumber],
"Metering Mode" = Getimageinfoval ($exif [Exif][meteringmode], $MeteringMode _arr),
"Light Source" = Getimageinfoval ($exif [Exif][lightsource], $Lightsource _arr),
"Flash" = Getimageinfoval ($exif [Exif][flash], $Flash _arr),
"Exposure Mode" = ($exif [exif][exposuremode]==1?] Manual ":" Auto "),
"White balance" = ($exif [exif][whitebalance]==1?] Manual ":" Auto "),
"Exposure Program" = $ExposureProgram [$exif [Exif][exposureprogram]],
/*
Brightness of taken subject, Unit is APEX. To calculate Exposure (Ev) from Brigtnessvalue (BV), you must add Sensitivityvalue (SV).
EV=BV+SV Sv=log ((isospeedrating/3.125), 2)
Iso100:sv=5, Iso200:sv=6, iso400:sv=7, iso125:sv=5.32.
*/
"Exposure compensation" = $exif [Exif][exposurebiasvalue]. " EV ",
"ISO Sensitivity" = $exif [Exif][isospeedratings],
"Component Configuration" = (Bin2Hex ($exif [exif][componentsconfiguration]) = = "01020300"? " YCbCr ":" RGB "),//' 0x04,0x05,0x06,0x00 ' =" RGB "' 0x01,0x02,0x03,0x00 ' =" YCbCr "
"image compression Rate" = $exif [Exif][compressedbitsperpixel]. " Bits/pixel ",
"Focus Distance" = $exif [computed][focusdistance]. " M ",
"Focal Length" = "$exif [exif][focallength]." MM ",
"Equivalent 35mm focal Length" = $exif [Exif][focallengthin35mmfilm]. " MM ",
/*
Stores user comment. This tag allows to use Two-byte character code or Unicode. First 8 bytes describe the character code. ' JIS ' is a Japanese character code (known as Kanji).
' 0x41,0x53,0x43,0x49,0x49,0x00,0x00,0x00 ': ASCII
' 0x4a,0x49,0x53,0x00,0x00,0x00,0x00,0x00 ': JIS
' 0x55,0x4e,0x49,0x43,0x4f,0x44,0x45,0x00 ': Unicode
' 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ': Undefined
*/
"User Comment Code" = $exif [computed][usercommentencoding],
User comments = $exif [Computed][usercomment],
"Color Space" = ($exif [exif][colorspace]==1?] SRGB ":" uncalibrated "),
"Exif image width" = $exif [Exif][exifimagelength],
"EXIF Image height" = $exif [Exif][exifimagewidth],
"File Source" = (Bin2Hex ($exif [Exif][filesource]) ==0x03? " Digital still Camera ":" Unknown "),
"Scene Type" = (Bin2Hex ($exif [exif][scenetype]) ==0x01? " A directly photographed image ":" Unknown "),
"Thumbnail file format" = $exif [Computed][thumbnail.filetype],
"Thumbnail MIME format" = = $exif [Computed][thumbnail.mimetype]
);
}
return $new _img_info;
}
5. Write the test code

Header ("Content-type:text/html;charset=utf-8");
$filename = "Test.jpg";
Require ' pic.class.php ';
$new _img_info = Getimageinfo ($filename);
echo $new _img_info;
foreach ($new _img_info as $key = + $section) {
echo $key. ":". $section. "";
}
?>
6. Results

File information:-----------------------------FileName: test.jpg file type: JPG file format: image/jpeg file size: 477883 timestamp: 2014-03-07 14:53:57 image information:--- --------------------------Photo Description: Sony DSC Manufacturer: Sony Model: dslr-a900 Direction: Top left Side horizontal resolution: 2400000/10000 inch Vertical resolution: 2400000/ 10000-inch creation software: Adobe Photoshop CS6 (Windows) Modified: 2014:01:13 14:02:59 Author: ycbcr position control: Copyright: Photography Copyright: Edit Copyright: Shooting information:------------------ -----------EXIF version: 0221FlashPix version: Ver. 0.00 Shooting Time: 2014:01:10 12:06:40 Digital time: 2014:01:10 12:06:40 shooting resolution High: 806 shooting resolution width : 1210 Iris: 761471/100000 shutter speed: 7965784/1000000 shutter aperture: f/14.0 maximum aperture value: f434/100 exposure time: 1/250F-NUMBER:14/1 metering Mode: Evaluation light: Unknown Flash: Unknown exposure mode: Auto White balance: AE Program: Aperture Pre-exposure compensation: -7/10eviso Sensitivity: 100 component configuration: RGB image Compression ratio: Bits/pixel focus Distance: M focal length: 120/10mm equivalent 35mm focal length: 12mm User Comment Code: User comments: Color space: uncalibratedexif image width: 4032Exif image height: 6048 file Source: Digital still camera scene type: A directly photographed image thumbnail file format: Thumbnail MIME format:

At this point, a simple use of the EXIF function set to display the image of the EXIF information module is out.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.