Example #1
0
 /**
  * Handle the creation of a new photo.
  * @todo Get tags from the XMP and/or IPTC data in the image
  *
  * @param Item_Model $photo
  */
 static function item_created($photo)
 {
     $tags = array();
     if ($photo->is_photo()) {
         $path = $photo->file_path();
         $size = getimagesize($photo->file_path(), $info);
         if (is_array($info) && !empty($info["APP13"])) {
             $iptc = iptcparse($info["APP13"]);
             if (!empty($iptc["2#025"])) {
                 foreach ($iptc["2#025"] as $tag) {
                     $tag = str_replace("", "", $tag);
                     foreach (explode(",", $tag) as $word) {
                         $word = trim($word);
                         $word = encoding::convert_to_utf8($word);
                         $tags[$word] = 1;
                     }
                 }
             }
         }
     }
     // @todo figure out how to read the keywords from xmp
     foreach (array_keys($tags) as $tag) {
         try {
             tag::add($photo, $tag);
         } catch (Exception $e) {
             Kohana_Log::add("error", "Error adding tag: {$tag}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         }
     }
     return;
 }
Example #2
0
 static function extract($item)
 {
     $keys = array();
     // Only try to extract EXIF from photos
     if ($item->is_photo() && $item->mime_type == "image/jpeg") {
         $data = array();
         require_once MODPATH . "exif/lib/exif.php";
         $exif_raw = read_exif_data_raw($item->file_path(), false);
         if (isset($exif_raw['ValidEXIFData'])) {
             foreach (self::_keys() as $field => $exifvar) {
                 if (isset($exif_raw[$exifvar[0]][$exifvar[1]])) {
                     $value = $exif_raw[$exifvar[0]][$exifvar[1]];
                     $value = encoding::convert_to_utf8($value);
                     $keys[$field] = Input::clean($value);
                     if ($field == "DateTime") {
                         $time = strtotime($value);
                         if ($time > 0) {
                             $item->captured = $time;
                         }
                     } else {
                         if ($field == "Caption" && !$item->description) {
                             $item->description = $value;
                         }
                     }
                 }
             }
         }
         $size = getimagesize($item->file_path(), $info);
         if (is_array($info) && !empty($info["APP13"])) {
             $iptc = iptcparse($info["APP13"]);
             foreach (array("Keywords" => "2#025", "Caption" => "2#120") as $keyword => $iptc_key) {
                 if (!empty($iptc[$iptc_key])) {
                     $value = implode(" ", $iptc[$iptc_key]);
                     $value = encoding::convert_to_utf8($value);
                     $keys[$keyword] = Input::clean($value);
                     if ($keyword == "Caption" && !$item->description) {
                         $item->description = $value;
                     }
                 }
             }
         }
     }
     $item->save();
     $record = ORM::factory("exif_record")->where("item_id", "=", $item->id)->find();
     if (!$record->loaded()) {
         $record->item_id = $item->id;
     }
     $record->data = serialize($keys);
     $record->key_count = count($keys);
     $record->dirty = 0;
     $record->save();
 }