How to display photo exif information in PHP

Source: Internet
Author: User
Tags foreach manual file size php programming

 php programming enables you to display photo exif information and display thumbnail effects in the picture, with the following code:

? /** * Functions to obtain image information * A function to obtain image information completely * @access public * @param string $img picture path * @return Array/function Getimageinfoval ($Im
  Ageinfo, $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 O
  Rder) "," 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 ("", "" "," inch "," cm ");
  $YCbCrPositioning = Array ("", "the center of Pixel Array", "The Datum point");
  $ExposureProgram = Array ("Undefined", "manual", "standard procedure", "Aperture precedent", "shutter precedent", "preliminary", "Motion Mode", "Portrait Mode", "landscape mode"); $MeteringMode _arr = Array ("0" =>) notKnowledge "," 1 "=>" average "," 2 "=>" Central focus average Metering "," 3 "=>" Point Measurement "," 4 "=>" Zoning "," 5 "=>
  "Evaluation", "6" => "local", "255" => "other"); $Lightsource _arr = Array ("0" => "Unknown", "1" => "Daylight", "2" => "Fluorescent", "3" => "tungsten wire  Lamp "," => "flash", "=>" "standard lighting a", "=>" standard light B "," => "standard lighting C", "the" =>
  "D55", "=>", "D65", "=>" "D75", "255" => "other"); $Flash _arr = Array ("0" => "Flash did not Fire", "1" => "Flash Fired", "5" => "Flas"
  
  H 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][fil  EType]], "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" =&  Gt $exif [Ifd0][imagedescription], "Manufacturer" => $exif [Ifd0][make], "model" => $exif [Ifd0][model], " Direction "=> $Orientation [$exif [ifd0][orientation]]," Horizontal resolution "=> $exif [ifd0][xresolution]. $ResolutionUnit [$ex
      If[ifd0][resolutionunit]], "vertical resolution" => $exif [ifd0][yresolution]. $ResolutionUnit [$exif [Ifd0][resolutionunit]], "Create software" => $exif [Ifd0][software], "Modify Time" => $exif [Ifd0][datetime], "author" => $exif [IFD 0][artist], "YCbCr position control" => $YCbCrPositioning [$exif [ifd0][ycbcrpositioning]], "copyright" => $exif [IFD0]
      [Copyright],"Photographic 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), "Filming Time" => $exif [exif][datetimeoriginal],  "Digitized Time" => $exif [exif][datetimedigitized], "Shoot resolution High" => $exif [computed][height], "Shoot 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 was ' 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], "photometric mode" => getimageinfoval ($exif [Exif][meteringmode], $MeteringMode _arr), "light source" => Geti Mageinfoval ($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 ": Automatic"), "exposure program" => $ExposureProgram [$exif [Exif][exposureprogram]],/* Brightness of taken Subje CT, Unit is APEX.
      To calculate exposure (EV) from Brigtnessvalue (BV), for 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][compressedbit Sperpixel]. " 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. The 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 annotations" => $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;
} $innerhtml = "";
$exif = Getimageinfo ($_get[' img '));

$innerhtml. = "<TABLE>"; foreach ($exif as $name => $val) {$innerhtml. = "<tr><td>{$name}</td><td>{$val}</td>&
Lt;/tr> ";
$innerhtml. = "<tr><td colspan=" 2 ">"; if ($_get[' img ']) {$image = Exif_thumbnail ($_get[' img '));} else {$image = false;} if ($image!==false) {$innerht ml. = "<img src=" thumbnail.php?img= "$_get[' img '". "
> "; else {//no thumbnail available, handle the error here $innerhtml. = "No ThumbnaIl available "; $innerhtml. = "</TD></TR></TABLE>"?> <html> <head> <title> picture information </TITLE&G
T <meta http-equiv= "Content-type" content= "text/html; charset=?????? " > </head> <body> <SCRIPT> <!--//initialization content value parent.followtd<?=$_get[' r_id '];? >.innerhtml= ' <?= $innerhtml;?
> '; Read parent.document.images.followimg<?=$_get[' r_id '];?
>.loaded= ' yes '; --> </SCRIPT> </body> </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.