Guest
Public paste!

Ivar

By: a guest | Jan 9th, 2010 | Syntax: PHP | Size: 3.57 KB | Hits: 129 | Expires: Never
Copy text to clipboard
  1. <?php
  2.  
  3. include("xmp_parser.php");
  4.  
  5. function xmp_parse($file) {
  6.     ob_start();
  7.     readfile($file);
  8.     $source = ob_get_contents();
  9.     ob_end_clean();
  10.    
  11.     $xmpdata_start = strpos($source,"<x:xmpmeta");
  12.     $xmpdata_end = strpos($source,"</x:xmpmeta>");
  13.     $xmplenght = $xmpdata_end-$xmpdata_start;
  14.     $xmpdata = substr($source,$xmpdata_start,$xmplenght+12);
  15.     $xmpdata = str_replace("\n","",$xmpdata);
  16.     //$xmpdata = str_replace("\t","",$xmpdata);
  17.    
  18.     $description_start = '<dc:description>    <rdf:Alt>     <rdf:li xml:lang="x-default">'; //hopefully the spaces are regular here.
  19.     $description_end   = '</rdf:li>';
  20.     $description = explode($description_start, $xmpdata);
  21.     $description = explode($description_end, $description[1]);
  22.     $description = $description[0];
  23.    
  24.     $lens_start = 'aux:Lens="';
  25.     $lens_end   = '" ';
  26.     $lens = explode($lens_start, $xmpdata);
  27.     $lens = explode($lens_end, $lens[1]);
  28.     $lens = $lens[0];
  29.    
  30.    
  31.     return Array('description' => $description, 'lens' => $lens);
  32. }
  33.  
  34. $files = glob("*.jpg");
  35. $images = Array();
  36. foreach ($files as $file) {
  37.     $exif = exif_read_data($file,0,true);
  38.     $cutline = $exif['IFD0']['ImageDescription'];
  39.     $shutter = $exif['EXIF']['ExposureTime'];
  40.     $aperture = $exif['COMPUTED']['ApertureFNumber'];
  41.     $datetime = $exif['EXIF']['DateTimeOriginal'];
  42.     $focallength = (int) $exif['EXIF']['FocalLength'];
  43.     $focallength .= "mm";
  44.     $iso = $exif['EXIF']['ISOSpeedRatings'];
  45.     $date_time_pieces = explode(" ", $datetime);
  46.     $_date = str_replace(":","-",$date_time_pieces[0]);
  47.     $_time = $date_time_pieces[1];
  48.        
  49.         $_iptc = Array();
  50.         getimagesize($file, $_iptc);
  51.         //print_r($_iptc);
  52.         $iptc = iptcparse($_iptc['APP13']);
  53.         $iptc_cutline = $iptc['2#120'][0];
  54.         //print_r($iptc);
  55.  
  56.     $xmp = xmp_parse($file);
  57.        
  58.  
  59.     $image = Array('file' => $file,
  60.                                'date' => $_date,
  61.                                    'time' => $_time,
  62.                                    'shutterspeed' => $shutter,
  63.                                    'aperture' => $aperture,
  64.                                    'focallength' => $focallength,
  65.                                    'iso' => $iso,
  66.                                    'cutline' => $cutline,
  67.                                    'iptc_cutline' => $iptc_cutline,
  68.                                    'xmp_cutline' => $xmp['description'],
  69.                                    'xmp_lens' => $xmp['lens']
  70.                                    );
  71.                                    
  72.     $images[$datetime] = $image;
  73.  
  74. }
  75.     krsort($images); //maintain keys, reverse sort
  76. ?>
  77.  
  78. <html>
  79.  
  80. <head>
  81.  
  82. <title>Ivar Vong Photography - 365</title>
  83.  
  84. <link href="365.css" rel="stylesheet" type="text/css">
  85.  
  86. </head>
  87.  
  88. <body>
  89.  
  90. <div class="wrapper">
  91.  
  92. <div class="header">
  93. <h2>365?</h2>
  94. </div>
  95.  
  96. <div class="images">
  97. <?php
  98. foreach ($images as $image) {
  99.     $content = "<div class='image'>\n";
  100.     $content .= "<strong>" . $image['date'] . "</strong> | " . $image['time'] . " | ";
  101.     $content .= $image['focallength'] . " | ";
  102.     $content .= $image['aperture'] . " | ";
  103.     $content .= $image['shutterspeed'] . " sec | ";
  104.     $content .= "ISO".$image['iso'] . "";
  105.     $content .= "<br>\n";
  106.     $file = $image['file'];
  107.     $content .= "<img src='$file' /><br>\n";
  108.     if ($image['cutline']) {
  109.         $content .= $image['cutline'] . "<br>\n";
  110.     } else if ($image['iptc_cutline']) {
  111.         $content .= $image['iptc_cutline'] . "<br>\n";
  112.     } else if ($image['xmp_cutline']) {
  113.         $content .= $image['xmp_cutline'] . "<br>\n";
  114.     } else {
  115.         $content .= "(no cutline information currently available)<br>\n";
  116.     }
  117.     $content .= "</div>\n\n";
  118.     echo $content;
  119.    
  120. }
  121. ?>
  122.  
  123. </div>
  124.  
  125. <?php
  126. echo "<br><br><br><br><br><br>\nDebug:<br>\n<pre>\n";
  127. print_r($images);
  128. echo "</pre>";
  129. ?>
  130.  
  131. </div>
  132.  
  133. </body>
  134. </html>