aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/exif.php57
1 files changed, 46 insertions, 11 deletions
diff --git a/lib/exif.php b/lib/exif.php
index 1b6c2cbd2..1bebb5fdc 100644
--- a/lib/exif.php
+++ b/lib/exif.php
@@ -1,14 +1,20 @@
<?php
include_once dirname(__FILE__) . "/tidypics.php";
-function td_get_exif(Elggfile $file) {
- $my_file = str_replace("image", "", tp_get_img_dir()) . $file->getFilename();
- $exif = exif_read_data($my_file);
+function td_get_exif($file_guid) {
+ $file = new ElggFile($file_guid);
+ $filename = $file->getFilenameOnFilestore();
+ $exif = exif_read_data($filename);
create_metadata($file->getGUID(), "tp_exif", serialize($exif), "string", $file->getObjectOwnerGUID(), 2);
}
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);
+ $metadata_exif = get_metadata_byname($file_guid, "tp_exif");
+ }
+
if($metadata_exif) {
$exif = unserialize($metadata_exif["value"]);
@@ -16,18 +22,47 @@ function tp_exif_formatted($file_guid) {
//convert the raw values to understandible values
$Fnumber = explode("/", $exif['FNumber']);
$Fnumber = $Fnumber[0] / $Fnumber[1];
+ if(!$Fnumber) {
+ $Fnumber = "N/A";
+ } else {
+ $Fnumber = "f/$Fnumber";
+ }
+
$Focal = explode("/", $exif['FocalLength']);
$Focal = $Focal[0] / $Focal[1];
+ if(!$Focal || round($Focal) == "0") $Focal = 0;
+ if(round($Focal) == 0) {
+ $Focal = "N/A";
+ } else {
+ $Focal = round($Focal) . "mm";
+ }
+
+ $model = $exif['Model'];
+ if(!$model) $model = "N/A";
+
+ $exposure = $exif['ExposureTime'];
+ if(!$exposure) $exposure = "N/A";
+
+ $iso = $exif['ISOSpeedRatings'];
+ if(!$iso) $iso = "N/A";
+
+ $captured = $exif['DateTime'];
+ if(!$captured) $captured = "N/A";
//prepare the text for return
- $exif_text = "Model: ".$exif['Model']."<br>";
- $exif_text .= "Shutter: ".$exif['ExposureTime']."<br>";
- $exif_text .= "Aperture: f/".$Fnumber."<br>";
- $exif_text .= "ISO Speed: ".$exif['ISOSpeedRatings']."<br>";
- $exif_text .= "Focal Length: ".round($Focal)."mm<br>";
- $exif_text .= "Captured: ". $exif['DateTime'];
-
- return "<tr><td>$exif_text</td></tr>";
+
+ $exif_text = "Model: ".$model."<br>";
+ $exif_text .= "Shutter: ".$exposure."<br>";
+ $exif_text .= "Aperture: ".$Fnumber."<br>";
+ $exif_text .= "ISO Speed: ".$iso."<br>";
+ if(round($Focal) == 0) {
+ $exif_text .= "Focal Length: N/A<br>";
+ } else {
+ $exif_text .= "Focal Length: " . round($Focal) . "mm<br />";
+ }
+ $exif_text .= "Captured: ". $captured;
+
+ return $exif_text;
} else {
return false;
}