diff options
-rw-r--r-- | actions/upload.php | 2 | ||||
-rw-r--r-- | lib/exif.php | 27 |
2 files changed, 22 insertions, 7 deletions
diff --git a/actions/upload.php b/actions/upload.php index da8af6e69..717c3274f 100644 --- a/actions/upload.php +++ b/actions/upload.php @@ -174,7 +174,7 @@ }
//get and store the exif data
- td_get_exif($file);
+ td_get_exif($file);
array_push($uploaded_images, $file->guid);
if($river_view == "all") {
diff --git a/lib/exif.php b/lib/exif.php index 1bebb5fdc..5382fbc9f 100644 --- a/lib/exif.php +++ b/lib/exif.php @@ -1,27 +1,39 @@ <?php include_once dirname(__FILE__) . "/tidypics.php"; -function td_get_exif($file_guid) { - $file = new ElggFile($file_guid); +function td_get_exif($file) { + $mime = $file->mimetype; + if ($mime != 'image/jpeg' && $mime != 'image/pjpeg') + return; + $filename = $file->getFilenameOnFilestore(); $exif = exif_read_data($filename); - create_metadata($file->getGUID(), "tp_exif", serialize($exif), "string", $file->getObjectOwnerGUID(), 2); + create_metadata($file->getGUID(), "tp_exif", serialize($exif), "string", $file->getObjectOwnerGUID(), ACCESS_PUBLIC); } function tp_exif_formatted($file_guid) { + $metadata_exif = get_metadata_byname($file_guid, "tp_exif"); if(!$metadata_exif) { //try to load it from the file if its not in the database - td_get_exif($file_guid); + $file = new ElggFile($file_guid); + td_get_exif($file); + unset($file); $metadata_exif = get_metadata_byname($file_guid, "tp_exif"); } if($metadata_exif) { + $exif = unserialize($metadata_exif["value"]); //got the code snippet below from http://www.zenphoto.org/support/topic.php?id=17 //convert the raw values to understandible values $Fnumber = explode("/", $exif['FNumber']); - $Fnumber = $Fnumber[0] / $Fnumber[1]; + + if ($Fnumber[1] != 0) + $Fnumber = $Fnumber[0] / $Fnumber[1]; + else + $Fnumber = 0; + if(!$Fnumber) { $Fnumber = "N/A"; } else { @@ -29,7 +41,10 @@ function tp_exif_formatted($file_guid) { } $Focal = explode("/", $exif['FocalLength']); - $Focal = $Focal[0] / $Focal[1]; + if ($Focal[1] != 0) + $Focal = $Focal[0] / $Focal[1]; + else + $Focal = 0; if(!$Focal || round($Focal) == "0") $Focal = 0; if(round($Focal) == 0) { $Focal = "N/A"; |