Retrieve EXIF info from jpg

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Retrieve EXIF info from jpg
function getexif($image,$format,$info) {
$date='';
$comment='';
if (file_exists($image) && extension_loaded('exif')) {
$extension=strtolower(substr($image,strrpos($image,'.')+1,strlen($image)));
if ($extension=='jpg' || $extension=='jpeg') {
$exif=@exif_read_data($image,0,true);
foreach($exif as $key=>$section) {
foreach($section as $name=>$val) {
if ($name=='DateTimeOriginal') {$date=$val;}
if ($name=='DateTime') {$date=$val;}
if ($name=='UserComment') {$comment.=$val . ' ';}
}
}
}
if ($date!='' && $date!="0000:00:00 00:00:00") {
$date=preg_replace("/(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})/",'\1-\2-\3 \4:\5:\6',$date);
$date=strtotime($date);
if ($date===-1) {$date=@filemtime($image);}
} else {
$date=@filemtime($image);
}
} else if (file_exists($image)) {
$date=@filemtime($image);
}
if ($format!='unix') {$date=date($format,$date);}
if ($info=='date')
return($date);
else
return(trim($comment));
}
?>