PHP method for retrieving Image exif attributes

Source: Internet
Author: User
PHP method for retrieving Image exif attributes & lt ;? Php *** function for retrieving image information ** a function for obtaining image information comprehensively ** & nbsp; @ access & nbsp; public * & nbsp; @ param & nbsp; string $ img Image path * & nbsp; @ return & nbsp; array * function & nbsp; GetImageInfoVal ($ ImageInfo, $ val_arr) & nbsp PHP method for retrieving Image exif attribute information

 /**
* Function for retrieving image information
*
* A function that comprehensively obtains image information
*
* @ Access public
* @ Param string $ img Image path
* @ Return array
*/
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 ", "right side top", "right side bottom", "left side bottom ");
$ ResolutionUnit = array ("", "", "inches", "centimeters ");
$ YCbCrPositioning = array ("", "the center of pixel array", "the datum point ");
$ ExposureProgram = array ("undefined", "manual", "Standard Program", "aperture prerequisite", "Shutter prerequisite", "Depth of field prerequisite", "motion mode ", "Portrait Mode", "Landscape mode ");
$ MeteringMode_arr = array (
"0" => "unknown ",
"1" => "average ",
"2" => "central key average light measurement ",
"3" => "spot test ",
"4" => "partition ",
"5" => "evaluation ",
"6" => "local ",
"255" => "other"
);
$ Lightsource_arr = array (
"0" => "unknown ",
"1" => "daylight ",
"2" => "fluorescent lights ",
"3" => "tungsten lamps ",
"10" => "Flashlight ",
"17" => "standard light ",
"18" => "standard light B ",
"19" => "standard light C ",
"20" => "D55 ",
"21" => "D65 ",
"22" => "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 Image 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" => "-----------------------------",
"Image description" => $ 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],
"Modification time" => $ exif [IFD0] [DateTime],
"Author" => $ exif [IFD0] [Artist],
"YCbCr location 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],
"Digitization time" => $ exif [EXIF] [DateTimeDigitized],
"High shooting resolution" => $ exif [COMPUTED] [Height],
"Shooting resolution Width" => $ exif [COMPUTED] [Width],
/*
The actual aperture value of lens when the image was 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 is '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 ),
"Flashlight" => GetImageInfoVal ($ exif [EXIF] [Flash], $ Flash_arr ),
"Exposure mode" => ($ exif [EXIF] [ExposureMode] = 1? "Manual": "Automatic "),
"White Balance" => ($ exif [EXIF] [WhiteBalance] = 1? "Manual": "Automatic "),
"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 = log (ISO speedrating/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 annotation encoding" => $ exif [COMPUTED] [UserCommentEncoding],
"User comment" => $ 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 "),
"Scenario 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;
}

$ Innerhtml = "";
$ Exif = GetImageInfo ($ _ GET ['IMG ']);
$ Innerhtml. ="





"; Foreach ($ exif as $ name => $ val ){$ Innerhtml. =" ";} $ Innerhtml. ="
{$ Name} {$ Val}
";
If ($ _ GET ['IMG ']) {
$ Image = exif_thumbnail ($ _ GET ['IMG ']);
} Else {
$ Image = false;
}
If ($ image! = False ){
$ Innerhtml. = "";
} Else {
// No thumbnail available, handle the error here
$ Innerhtml. = "No thumbnail available ";
}

$ Innerhtml. ="
";
?>


Image information



SCRIPT

SCRIPT

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.