static function update_index($task) { 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")->and_open()->where("exif_records.item_id", "IS", null)->or_where("exif_records.dirty", "=", 1)->close()->find_all() as $item) { // The query above can take a long time, so start the timer after its done // to give ourselves a little time to actually process rows. if (!isset($start)) { $start = microtime(true); } exif::extract($item); $completed++; if (microtime(true) - $start > 1.5) { break; } } 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 = "error"; $task->status = $e->getMessage(); $task->log((string) $e); } }
static function update_index($task) { 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; } $completed++; exif::extract($item); } 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 = "error"; $task->status = $e->getMessage(); $task->log($e->__toString()); } }
/** * Display the EXIF data for an item. */ public function show($item_id) { $item = ORM::factory("item", $item_id); access::required("view", $item); $view = new View("exif_dialog.html"); $view->details = exif::get($item); print $view; }
public function exif_extract_test() { $rand = rand(); $root = ORM::factory("item", 1); $photo = photo::create($root, MODPATH . "exif/tests/data/image.jpg", "{$rand}.jpg", $rand, $rand); $expected = array(array("caption" => "Camera Maker", "value" => "Pentax Corporation"), array("caption" => "Camera Model", "value" => "PENTAX K10D"), array("caption" => "Aperture", "value" => "f/2.8"), 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" => "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)"), array("caption" => "Resolution Unit", "value" => "Inch"), array("caption" => "X Resolution", "value" => "240 dots per ResolutionUnit"), array("caption" => "Y Resolution", "value" => "240 dots per ResolutionUnit"), array("caption" => "Brightness Value", "value" => "0"), array("caption" => "Scene Type", "value" => "0"), array("caption" => "Subject Distance", "value" => "0")); $this->assert_equal($expected, exif::get($photo)); }
static function activate() { exif::check_index(); }
static function check_index() { list($remaining) = exif::stats(); if ($remaining) { site_status::warning(t('Your Exif index needs to be updated. <a href="%url" class="g-dialog-link">Fix this now</a>', array("url" => html::mark_clean(url::site("admin/maintenance/start/exif_task::update_index?csrf=__CSRF__")))), "exif_index_out_of_date"); } }
static function item_created($item) { if (!$item->is_album()) { exif::extract($item); } }
<?php // This script will return to flash an XML with some IPTC and EXIF fields DEFINE('IPTC_CAPTION', '120'); // 2000 chars DEFINE('IPTC_CITY', '090'); // 32 chars DEFINE('IPTC_GLOBAL_POSITION', '092'); // improvisation for wikimapia geodata DEFINE('EXIF_GEO_LAT', 'GPSLatitude'); DEFINE('EXIF_GEO_LAT_REF', 'GPSLatitudeRef'); DEFINE('EXIF_GEO_LON', 'GPSLongitude'); DEFINE('EXIF_GEO_LON_REF', 'GPSLongitudeRef'); DEFINE('EXIF_EXPOSURE', 'ExposureTime'); DEFINE('EXIF_APERTURE', 'FNumber'); DEFINE('EXIF_FOCAL_LENGTH', 'FocalLength'); DEFINE('EXIF_ISO', 'ISOSpeedRatings'); include "iptc.php"; include "exif.php"; $path = "../../" . $_POST['path']; $i = new iptc($path); $e = new exif($path); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><info>" . "<caption><![CDATA[" . $i->get(IPTC_CAPTION) . "]]></caption>" . "<city><![CDATA[" . $i->get(IPTC_CITY) . "]]></city>" . "<location><![CDATA[" . $i->get(IPTC_GLOBAL_POSITION) . "]]></location>" . "<geodata>" . $e->getGPS(EXIF_GEO_LAT, EXIF_GEO_LAT_REF) . "+" . $e->getGPS(EXIF_GEO_LON, EXIF_GEO_LON_REF) . "</geodata>" . "<exposure>" . $e->getEXIF(EXIF_EXPOSURE) . "</exposure>" . "<aperture>" . $e->getDividedEXIF(EXIF_APERTURE) . "</aperture>" . "<focallength>" . $e->getDividedEXIF(EXIF_FOCAL_LENGTH) . "</focallength>" . "<iso>" . $e->getEXIF(EXIF_ISO) . "</iso>" . "</info>";
public function exif_extract_test() { $photo = test::random_photo_unsaved()->set_data_file(MODPATH . "exif/tests/data/image.jpg")->save(); $expected = array(array("caption" => "Camera Maker", "value" => "Pentax Corporation"), array("caption" => "Camera Model", "value" => "PENTAX K10D"), array("caption" => "Aperture", "value" => "f/2.8"), 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" => "100"), array("caption" => "Metering Mode", "value" => "Pattern"), 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)"), array("caption" => "Resolution Unit", "value" => "Inch"), array("caption" => "X Resolution", "value" => "240 dots per ResolutionUnit"), array("caption" => "Y Resolution", "value" => "240 dots per ResolutionUnit"), array("caption" => "Brightness Value", "value" => "0"), array("caption" => "Scene Type", "value" => "0"), array("caption" => "Subject Distance", "value" => "0")); $this->assert_equal($expected, exif::get($photo)); }
static function item_updated_data_file($item) { if (!$item->is_album()) { exif::extract($item); } }
function assignDate($integer, $albumGet) { if ($this->photos) { $exif = new exif(); $result = @$exif->read_exif_data_raw(dirRoot . '/' . $albumGet . '/' . imageDir . $this->photos[$integer]['name'], "yes"); $time = $result['SubIFD']['DateTimeOriginal']; $hour = preg_replace('/([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/', '$4', $time); $minute = preg_replace('/([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/', '$5', $time); $second = preg_replace('/([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/', '$6', $time); $month = preg_replace('/([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/', '$2', $time); $day = preg_replace('/([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/', '$3', $time); $year = preg_replace('/([0-9]+):([0-9]+):([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/', '$1', $time); $timestamp = mktime($hour, $minute, $second, $month, $day, $year); /*temporary*/ #if ($time == '' or $year == 0000) { $timestamp = @filemtime(dirRoot . '/' . $albumGet . '/' . imageDir . $this->photos[$integer]['name']); #} $this->photos[$integer]['date'] = $timestamp; if ($integer = 1 && !isset($this->albums[$albumGet]['date'])) { $this->albums[$albumGet]['date'] = $this->photos[$integer]['date']; } } }
static function item_created($item) { exif::extract($item); }