diff options
Diffstat (limited to 'modules/exif')
-rw-r--r-- | modules/exif/helpers/exif.php | 60 | ||||
-rw-r--r-- | modules/exif/helpers/exif_task.php | 69 | ||||
-rw-r--r-- | modules/exif/lib/exif.php | 38 | ||||
-rw-r--r-- | modules/exif/module.info | 2 | ||||
-rw-r--r-- | modules/exif/tests/Exif_Test.php | 2 |
5 files changed, 81 insertions, 90 deletions
diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index 970be5ac..20ecd0cb 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -104,35 +104,35 @@ class exif_Core { private static function _keys() { if (!isset(self::$exif_keys)) { self::$exif_keys = array( - "Make" => array("IFD0", "Make", t("Camera Maker"), true), - "Model" => array("IFD0", "Model", t("Camera Model"), true), - "Aperture" => array("SubIFD", "FNumber", t("Aperture"), true), - "ColorSpace" => array("SubIFD", "ColorSpace", t("Color Space"), true), - "ExposureBias" => array("SubIFD", "ExposureBiasValue", t("Exposure Value"), true), - "ExposureProgram" => array("SubIFD", "ExposureProgram", t("Exposure Program"), true), - "Flash" => array("SubIFD", "Flash", t("Flash"), true), - "FocalLength" => array("SubIFD", "FocalLength", t("Focal Length"), true), - "ISO" => array("SubIFD", "ISOSpeedRatings", t("ISO"), true), - "MeteringMode" => array("SubIFD", "MeteringMode", t("Metering Mode"), true), - "ShutterSpeed" => array("SubIFD", "ShutterSpeedValue", t("Shutter Speed"), true), - "DateTime" => array("SubIFD", "DateTimeOriginal", t("Date/Time"), true), - "Copyright" => array("IFD0", "Copyright", t("Copyright"), false), - "ImageType" => array("IFD0", "ImageType", t("Image Type"), false), - "Orientation" => array("IFD0", "Orientation", t("Orientation"), false), - "ResolutionUnit" => array("IFD0", "ResolutionUnit", t("Resolution Unit"), false), - "xResolution" => array("IFD0", "xResolution", t("X Resolution"), false), - "yResolution" => array("IFD0", "yResolution", t("Y Resolution"), false), - "Compression" => array("IFD1", "Compression", t("Compression"), false), - "BrightnessValue" => array("SubIFD", "BrightnessValue", t("Brightness Value"), false), - "Contrast" => array("SubIFD", "Contrast", t("Contrast"), false), - "ExposureMode" => array("SubIFD", "ExposureMode", t("Exposure Mode"), false), - "FlashEnergy" => array("SubIFD", "FlashEnergy", t("Flash Energy"), false), - "Saturation" => array("SubIFD", "Saturation", t("Saturation"), false), - "SceneType" => array("SubIFD", "SceneType", t("Scene Type"), false), - "Sharpness" => array("SubIFD", "Sharpness", t("Sharpness"), false), - "SubjectDistance" => array("SubIFD", "SubjectDistance", t("Subject Distance"), false), - "Caption" => array("IPTC", "Caption", t("Caption"), false), - "Keywords" => array("IPTC", "Keywords", t("Keywords"), false) + "Make" => array("IFD0", "Make", t("Camera Maker"), ), + "Model" => array("IFD0", "Model", t("Camera Model"), ), + "Aperture" => array("SubIFD", "FNumber", t("Aperture"), ), + "ColorSpace" => array("SubIFD", "ColorSpace", t("Color Space"), ), + "ExposureBias" => array("SubIFD", "ExposureBiasValue", t("Exposure Value"), ), + "ExposureProgram" => array("SubIFD", "ExposureProgram", t("Exposure Program"), ), + "ExposureTime" => array("SubIFD", "ExposureTime", t("Exposure Time"), ), + "Flash" => array("SubIFD", "Flash", t("Flash"), ), + "FocalLength" => array("SubIFD", "FocalLength", t("Focal Length"), ), + "ISO" => array("SubIFD", "ISOSpeedRatings", t("ISO"), ), + "MeteringMode" => array("SubIFD", "MeteringMode", t("Metering Mode"), ), + "DateTime" => array("SubIFD", "DateTimeOriginal", t("Date/Time"), ), + "Copyright" => array("IFD0", "Copyright", t("Copyright"), ), + "ImageType" => array("IFD0", "ImageType", t("Image Type"), ), + "Orientation" => array("IFD0", "Orientation", t("Orientation"), ), + "ResolutionUnit" => array("IFD0", "ResolutionUnit", t("Resolution Unit"), ), + "xResolution" => array("IFD0", "xResolution", t("X Resolution"), ), + "yResolution" => array("IFD0", "yResolution", t("Y Resolution"), ), + "Compression" => array("IFD1", "Compression", t("Compression"), ), + "BrightnessValue" => array("SubIFD", "BrightnessValue", t("Brightness Value"), ), + "Contrast" => array("SubIFD", "Contrast", t("Contrast"), ), + "ExposureMode" => array("SubIFD", "ExposureMode", t("Exposure Mode"), ), + "FlashEnergy" => array("SubIFD", "FlashEnergy", t("Flash Energy"), ), + "Saturation" => array("SubIFD", "Saturation", t("Saturation"), ), + "SceneType" => array("SubIFD", "SceneType", t("Scene Type"), ), + "Sharpness" => array("SubIFD", "Sharpness", t("Sharpness"), ), + "SubjectDistance" => array("SubIFD", "SubjectDistance", t("Subject Distance"), ), + "Caption" => array("IPTC", "Caption", t("Caption"), ), + "Keywords" => array("IPTC", "Keywords", t("Keywords"), ) ); } return self::$exif_keys; @@ -163,7 +163,7 @@ class exif_Core { list ($remaining) = exif::stats(); if ($remaining) { site_status::warning( - t('Your EXIF index needs to be updated. <a href="%url" class="gDialogLink">Fix this now</a>', + t('Your Exif index needs to be updated. <a href="%url" class="gDialogLink">Fix this now</a>', array("url" => url::site("admin/maintenance/start/exif_task::update_index?csrf=__CSRF__"))), "exif_index_out_of_date"); } diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index 375503e3..f3e77975 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -28,47 +28,58 @@ class exif_task_Core { list ($remaining, $total, $percent) = exif::stats(); return array(Task_Definition::factory() ->callback("exif_task::update_index") - ->name(t("Extract EXIF data")) + ->name(t("Extract Exif data")) ->description($remaining ? t2("1 photo needs to be scanned", "%count (%percent%) of your photos need to be scanned", $remaining, array("percent" => (100 - $percent))) - : t("EXIF data is up-to-date")) + : t("Exif data is up-to-date")) ->severity($remaining ? log::WARNING : log::SUCCESS)); } static function update_index($task) { - $completed = $task->get("completed", 0); + try { + $completed = $task->get("completed", 0); - $start = microtime(true); - foreach (ORM::factory("item") - ->join("exif_records", "items.id", "exif_records.item_id", "left") - ->where("type", "photo") - ->open_paren() - ->where("exif_records.item_id", null) - ->orwhere("exif_records.dirty", 1) - ->close_paren() - ->find_all() as $item) { - if (microtime(true) - $start > 1.5) { - break; - } + $start = microtime(true); + $message = array(); + foreach (ORM::factory("item") + ->join("exif_records", "items.id", "exif_records.item_id", "left") + ->where("type", "photo") + ->open_paren() + ->where("exif_records.item_id", null) + ->orwhere("exif_records.dirty", 1) + ->close_paren() + ->find_all() as $item) { + if (microtime(true) - $start > 1.5) { + break; + } - $completed++; - exif::extract($item); - } + $completed++; + exif::extract($item); + $message[] = t("Updated Exif meta data for '%title'", + array("title" => p::purify($item->title))); + } - list ($remaining, $total, $percent) = exif::stats(); - $task->set("completed", $completed); - if ($remaining == 0 || !($remaining + $completed)) { + $task->log($message); + list ($remaining, $total, $percent) = exif::stats(); + $task->set("completed", $completed); + if ($remaining == 0 || !($remaining + $completed)) { + $task->done = true; + $task->state = "success"; + site_status::clear("exif_index_out_of_date"); + $task->percent_complete = 100; + } else { + $task->percent_complete = round(100 * $completed / ($remaining + $completed)); + } + $task->status = t2("one record updated, index is %percent% up-to-date", + "%count records updated, index is %percent% up-to-date", + $completed, array("percent" => $percent)); + } catch (Exception $e) { $task->done = true; - $task->state = "success"; - site_status::clear("exif_index_out_of_date"); - $task->percent_complete = 100; - } else { - $task->percent_complete = round(100 * $completed / ($remaining + $completed)); + $task->state = "error"; + $task->status = $e->getMessage(); + $task->log($e->__toString()); } - $task->status = t2("one record updated, index is %percent% up-to-date", - "%count records updated, index is %percent% up-to-date", - $completed, array("percent" => $percent)); } } diff --git a/modules/exif/lib/exif.php b/modules/exif/lib/exif.php index f335dad4..bd72f237 100644 --- a/modules/exif/lib/exif.php +++ b/modules/exif/lib/exif.php @@ -1007,35 +1007,15 @@ if ($result['ValidJpeg'] == 1) { //================================================================================================ function ConvertToFraction($v, &$n, &$d) { - $MaxTerms = 15; // Limit to prevent infinite loop - $MinDivisor = 0.000001; // Limit to prevent divide by zero - $MaxError = 0.00000001; // How close is enough - - $f = $v; // Initialize fraction being converted - - $n_un = 1; // Initialize fractions with 1/0, 0/1 - $d_un = 0; - $n_deux = 0; - $d_deux = 1; - - for ($i = 0; $i<$MaxTerms; $i++) - { - $a = floor($f); // Get next term - $f = $f - $a; // Get new divisor - $n = $n_un * $a + $n_deux; // Calculate new fraction - $d = $d_un * $a + $d_deux; - $n_deux = $n_un; // Save last two fractions - $d_deux = $d_un; - $n_un = $n; - $d_un = $d; - - if ($f < $MinDivisor) // Quit if dividing by zero - break; - - if (abs($v - $n / $d) < $MaxError) - break; - - $f = 1 / $f; // Take reciprocal + if ($v == 0) { + $n = 0; + $d = 1; + return; + } + for ($n=1; $n<100; $n++) { + $v1 = 1/$v*$n; + $d = round($v1, 0); + if (abs($d - $v1) < 0.02) return;// within tolarance } } diff --git a/modules/exif/module.info b/modules/exif/module.info index 1e16a5ff..c8ae688e 100644 --- a/modules/exif/module.info +++ b/modules/exif/module.info @@ -1,3 +1,3 @@ -name = Exif Data +name = "Exif Data" description = "Extract Exif data and display it on photo pages." version = 1 diff --git a/modules/exif/tests/Exif_Test.php b/modules/exif/tests/Exif_Test.php index 312ed535..5c5a5cb1 100644 --- a/modules/exif/tests/Exif_Test.php +++ b/modules/exif/tests/Exif_Test.php @@ -31,11 +31,11 @@ class Exif_Test extends Unit_Test_Case { array("caption" => "Color Space", "value" => "Uncalibrated"), array("caption" => "Exposure Value", "value" => "4294.67 EV"), array("caption" => "Exposure Program", "value" => "Program"), + array("caption" => "Exposure Time", "value" => "1/60 sec"), array("caption" => "Flash", "value" => "No Flash"), array("caption" => "Focal Length", "value" => "50 mm"), array("caption" => "ISO", "value" => "6553700"), array("caption" => "Metering Mode", "value" => "Multi-Segment"), - array("caption" => "Shutter Speed", "value" => "1/60 sec"), array("caption" => "Date/Time", "value" => "2008:03:17 17:41:25"), array("caption" => "Copyright", "value" => "(C) 2008 - T. Almdal"), array("caption" => "Orientation", "value" => "1: Normal (0 deg)"), |