How to display the exif information of a photo in PHP

Source: Internet
Author: User

How to display the exif information of a photo in PHP

PHP programming allows you to display the EXIF information of a photo and display the thumbnail effect in the image. The Code is as follows:

<? /*** Function for obtaining image information * a function for fully obtaining 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 orde R) "," 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" => "test", "4" => "partition", "5" => "evaluation", "6" => "local ", "255" => "other"); $ Lightsource_arr = array ("0" => "unknown", "1" => "daylight ", "2" => "Fluorescent Lamps", "3" => "tungsten lamps", "10" => "Flashlight", "17" => "standard lamps ", "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. photo Grapher], "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 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, 0x00 ': JIS '0x55, 0x4e, 0x49,0x43, 0x4f, 0x44,0x45, 0x00': Unicode '0x00, 0 x, 0 x, 0 x, 0 x, 0 x, 0x00, 0x00': Undefined */"User annotation encoding" => $ 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"), "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. = "<TABLE>"; foreach ($ exif as $ name => $ val) {$ innerhtml. = "<TR> <TD >{$ name} </TD> <TD >{$ val} </TD> </TR>" ;}$ innerhtml. = "<TR> <TD colspan = \" 2 \ ">"; if ($ _ GET ['img ']) {$ imag E = exif_thumbnail ($ _ GET ['img ']);} else {$ image = false;} if ($ image! = False) {$ innerhtml. = " ";} else {// no thumbnail available, handle the error here $ innerhtml. = "No thumbnail available";} $ innerhtml. = "</TD> </TR> </TABLE>";?> <Html> 
 

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.