[ansel] Patch to Exif.php to reformat dates from image EXIF values
Heath S. Hendrickson
heath at outerspaceconsultants.com
Wed May 19 18:51:38 PDT 2004
Attached are patches to lib/Exif.php and search.php that will take the
EXIF date and convert it to a timestamp before storing it in the datatree.
I also patched templates/search/search.html to make the table heading
for description consistent with what it's called elsewhere in Ansel,
caption.
I'll see if I can get something done with the search form to handle the
dates specially... I'm probably going to start by splitting the
date-based attributes out into their own form (on the same page) to
avoid any user confusion.
h
-------------- next part --------------
Index: templates/search/search.html
===================================================================
RCS file: /usr/local/horde/cvs/ansel/templates/search/search.html,v
retrieving revision 1.1
diff -u -r1.1 search.html
--- templates/search/search.html 18 May 2004 15:25:29 -0000 1.1
+++ templates/search/search.html 20 May 2004 01:46:22 -0000
@@ -6,7 +6,7 @@
<tr>
<td class="control"><b><gettext>Image</gettext></b></td>
<td class="control"><b><gettext>Gallery</gettext></b></td>
- <td class="control"><b><gettext>Description</gettext></b></td>
+ <td class="control"><b><gettext>Caption</gettext></b></td>
</tr>
<loop:images>
-------------- next part --------------
Index: search.php
===================================================================
RCS file: /usr/local/horde/cvs/ansel/search.php,v
retrieving revision 1.5
diff -u -r1.5 search.php
--- search.php 18 May 2004 15:25:28 -0000 1.5
+++ search.php 20 May 2004 01:46:33 -0000
@@ -31,11 +31,18 @@
$fields = Ansel_ImageData::getFields();
// Now add on any others that we may want.
- $fields = array_merge($fields, array('description' => _("Description"),
- 'date-uploaded' => _("Date Uploaded"),
- 'filename' => _("Filename"),
- 'gallery' => _("Gallery Name")));
- asort($fields);
+ $fields += array('description' => array( 'description' => _("Description"), 'type' => 'text'),
+ 'date-uploaded' => array( 'description' => _("Date Uploaded"), 'type' => 'date'),
+ 'filename' => array( 'description' => _("Filename"), 'type' => 'text'),
+ 'gallery' => array( 'description' => _("Gallery Name"), 'type' => 'text'));
+
+ // reformat the array so that the Form Renderer likes it
+ $searchFields = array();
+ foreach( $fields as $field => $data) {
+ $searchFields += array( $field => $data['description'] );
+ }
+
+ asort($searchFields);
$ops = array('=' => _("Is"),
'!=' => _("Is Not"),
@@ -44,7 +51,7 @@
'LIKE' => _("Contains"),
'NOT LIKE' => _("Does Not Contain"));
- $this->addVariable(_("Field"), 'field', 'enum', false, false, null, array($fields));
+ $this->addVariable(_("Field"), 'field', 'enum', false, false, null, array($searchFields));
$this->addVariable(_("Operator"), 'op', 'enum', false, false, null, array($ops));
$this->addVariable(_("Value"), 'value', 'text', false, false, null);
}
-------------- next part --------------
Index: lib/Exif.php
===================================================================
RCS file: /usr/local/horde/cvs/ansel/lib/Exif.php,v
retrieving revision 1.15
diff -u -r1.15 Exif.php
--- lib/Exif.php 15 May 2004 23:57:29 -0000 1.15
+++ lib/Exif.php 19 May 2004 20:41:34 -0000
@@ -19,7 +19,7 @@
$fields = Ansel_ImageData::getFields();
$output = array();
- foreach ($fields as $field => $description) {
+ foreach ($fields as $field => $data) {
$value = $image->get($field);
if ($value === null) {
// Skip fields that weren't set.
@@ -27,6 +27,7 @@
}
$value = Ansel_ImageData::getHumanReadable($field, $value);
+ $description = isset($data['description']) ? $data['description'] : $field;
$output[] = '<td class="item"><b>' . $description . '</b>:</td><td class="item">' . htmlspecialchars($value) . '</td>';
}
return $output;
@@ -66,7 +67,7 @@
// See if we got any attributes back.
if (count($result)) {
$fields = Ansel_ImageData::getFields();
- foreach ($fields as $field => $desc) {
+ foreach ($fields as $field => $data) {
$value = isset($result[$field]) ? $result[$field] : '';
// Don't store empty fields.
@@ -74,6 +75,13 @@
continue;
}
+ // if the field is a date field, convert the value to a timestamp
+ if ($data['type'] == "date") {
+ list($ymd, $hms) = split(" ", $value, 2);
+ list($year, $month, $day) = split(":",$ymd, 3);
+ $time = "$month/$day/$year $hms";
+ $value = strtotime($time);
+ }
$image->set($field, $value);
}
@@ -263,9 +271,19 @@
case 'ColorSpace':
switch ($data) {
- case 1: return _("sRGB");
+ case 1:
+ return _("sRGB");
+ break;
+ default:
+ return _("Uncalibrated");
}
- return _("Uncalibrated");
+ break;
+
+ case 'DateTime':
+ case 'DateTimeOriginal':
+ case 'DateTimeDigitized':
+ return date("m/d/Y h:i:s O", $data);
+ break;
default:
return $data;
@@ -281,35 +299,35 @@
*/
function getFields()
{
- return array('Make' => _("Camera Make"),
- 'Model' => _("Camera Model"),
- 'ImageType' => _("Image Type"),
- 'FileSize' => _("File Size"),
- 'DateTime' => _("Date Image Modified"),
- 'DateTimeOriginal' => _("Date Image Taken"),
- 'DateTimeDigitized' => _("Date Image Digitized"),
- 'ExifImageWidth' => _("Width"),
- 'ExifImageLength' => _("Height"),
- 'XResolution' => _("X Resolution"),
- 'YResolution' => _("Y Resolution"),
- 'ShutterSpeedValue' => _("Shutter Speed"),
- 'ExposureTime' => _("Exposure"),
- 'FocalLength' => _("Focal Length"),
- 'FocalLengthIn35mmFilm' => _("Focal Length (35mm equiv)"),
- 'ApertureValue' => _("Aperture"),
- 'FNumber' => _("F-Number"),
- 'ISOSpeedRatings' => _("ISO Setting"),
- 'ExposureBiasValue' => _("Exposure Bias"),
- 'ExposureMode' => _("Exposure Mode"),
- 'MeteringMode' => _("Metering Mode"),
- 'Flash' => _("Flash Setting"),
- 'UserComment' => _("User Comment"),
- 'ColorSpace' => _("Color Space"),
- 'SensingMethod' => _("Sensing Method"),
- 'WhiteBalance' => _("White Balance"),
- 'Orientation' => _("Camera Orientation"),
- 'Copyright' => _("Copyright"),
- 'Artist' => _("Artist")
+ return array('Make' => array( 'description' => _("Camera Make"), 'type' => 'text'),
+ 'Model' => array( 'description' => _("Camera Model"), 'type' => 'text'),
+ 'ImageType' => array( 'description' => _("Image Type"), 'type' => 'text'),
+ 'FileSize' => array( 'description' => _("File Size"), 'type' => 'number'),
+ 'DateTime' => array( 'description' => _("Date Image Modified"), 'type' => 'date'),
+ 'DateTimeOriginal' => array( 'description' => _("Date Image Taken"), 'type' => 'date'),
+ 'DateTimeDigitized' => array( 'description' => _("Date Image Digitized"), 'type' => 'date'),
+ 'ExifImageWidth' => array( 'description' => _("Width"), 'type' => 'number'),
+ 'ExifImageLength' => array( 'description' => _("Height"), 'type' => 'number'),
+ 'XResolution' => array( 'description' => _("X Resolution"), 'type' => 'number'),
+ 'YResolution' => array( 'description' => _("Y Resolution"), 'type' => 'number'),
+ 'ShutterSpeedValue' => array( 'description' => _("Shutter Speed"), 'type' => 'number'),
+ 'ExposureTime' => array( 'description' => _("Exposure"), 'type' => 'number'),
+ 'FocalLength' => array( 'description' => _("Focal Length"), 'type' => 'number'),
+ 'FocalLengthIn35mmFilm' => array( 'description' => _("Focal Length (35mm equiv)"), 'type' => 'number'),
+ 'ApertureValue' => array( 'description' => _("Aperture"), 'type' => 'number'),
+ 'FNumber' => array( 'description' => _("F-Number"), 'type' => 'number'),
+ 'ISOSpeedRatings' => array( 'description' => _("ISO Setting"), 'type' => 'number'),
+ 'ExposureBiasValue' => array( 'description' => _("Exposure Bias"), 'type' => 'number'),
+ 'ExposureMode' => array( 'description' => _("Exposure Mode"), 'type' => 'number'),
+ 'MeteringMode' => array( 'description' => _("Metering Mode"), 'type' => 'number'),
+ 'Flash' => array( 'description' => _("Flash Setting"), 'type' => 'number'),
+ 'UserComment' => array( 'description' => _("User Comment"), 'type' => 'text'),
+ 'ColorSpace' => array( 'description' => _("Color Space"), 'type' => 'number'),
+ 'SensingMethod' => array( 'description' => _("Sensing Method"), 'type' => 'number'),
+ 'WhiteBalance' => array( 'description' => _("White Balance"), 'type' => 'number'),
+ 'Orientation' => array( 'description' => _("Camera Orientation"), 'type' => 'number'),
+ 'Copyright' => array( 'description' => _("Copyright"), 'type' => 'text'),
+ 'Artist' => array( 'description' => _("Artist"), 'type' => 'text')
);
}
More information about the ansel
mailing list