function title_and_caption_not_utf8($meta, $file) { if (!file_exists($file)) { return false; } list(, , $sourceImageType) = getimagesize($file); $meta = array(); if (is_callable('iptcparse')) { getimagesize($file, $info); if (!empty($info['APP13'])) { $iptc = iptcparse($info['APP13']); // headline, "A brief synopsis of the caption." if (!empty($iptc['2#105'][0])) { $meta['title'] = trim($iptc['2#105'][0]); } elseif (!empty($iptc['2#005'][0])) { $meta['title'] = trim($iptc['2#005'][0]); } if (!empty($iptc['2#120'][0])) { // description / legacy caption $caption = trim($iptc['2#120'][0]); if (empty($meta['title'])) { // Assume the title is stored in 2:120 if it's short. if (strlen($caption) < 80) { $meta['title'] = $caption; } else { $meta['caption'] = $caption; } } elseif ($caption != $meta['title']) { $meta['caption'] = $caption; } } } } return $meta; }
/** * Class constructor * * @param int $image Image ID * @param bool $onlyEXIF TRUE = will parse only EXIF data * @return bool FALSE if the file does not exist or metadat could not be read */ public function __construct($image, $onlyEXIF = FALSE) { if (is_numeric($image)) { $image = $this->get_registry()->get_utility('I_Image_Mapper')->find($image); } $this->image = apply_filters('ngg_find_image_meta', $image); $this->file_path = $this->get_registry()->get_utility('I_Gallery_Storage')->get_image_abspath($this->image); if (!@file_exists($this->file_path)) { return FALSE; } $this->size = @getimagesize($this->file_path, $metadata); if ($this->size && is_array($metadata)) { // get exif - data if (is_callable('exif_read_data')) { $this->exif_data = @exif_read_data($this->file_path, 0, TRUE); } // stop here if we didn't need other meta data if ($onlyEXIF) { return TRUE; } // get the iptc data - should be in APP13 if (is_callable('iptcparse') && isset($metadata['APP13'])) { $this->iptc_data = @iptcparse($metadata['APP13']); } // get the xmp data in a XML format if (is_callable('xml_parser_create')) { $this->xmp_data = $this->extract_XMP($this->file_path); } return TRUE; } return FALSE; }
/** * Get important EXIF information from the image * @since Version 3.10.0 * @return array * @param \Railpage\Gallery\Image $imageObject */ public static function PopulateExif($imageObject) { $imageSource = Album::ALBUMS_DIR . $imageObject->path; /** * Read the IPTC data */ #$size = getimagesize($imageSource, $info); if (is_array($info)) { $iptc = iptcparse($info["APP13"]); if (isset($iptc['2#005'])) { $imageObject->title = $iptc['2#005'][0]; } } /** * Read the EXIF data */ $exif = exif_read_data($imageSource, 0, true); if (isset($exif['IFD0']['ImageDescription'])) { $imageObject->caption = $exif['IFD0']['ImageDescription']; } if (isset($exif['EXIF']['DateTimeOriginal'])) { $imageObject->DateTaken = new DateTime($exif['EXIF']['DateTimeOriginal']); } if (isset($exif['GPS']['GPSLatitude']) && isset($exif['GPS']['GPSLongitude'])) { $lat = self::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']); $lon = self::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']); $imageObject->Place = Place::Factory($lat, $lon); } return $imageObject; }
/** * nggMeta::nggMeta() * * @param int $image path to a image * @param bool $onlyEXIF parse only exif if needed * @return */ function nggMeta($pic_id, $onlyEXIF = false) { //get the path and other data about the image $this->image = nggdb::find_image($pic_id); $this->image = apply_filters('ngg_find_image_meta', $this->image); if (!file_exists($this->image->imagePath)) { return false; } $this->size = @getimagesize($this->image->imagePath, $metadata); if ($this->size && is_array($metadata)) { // get exif - data if (is_callable('exif_read_data')) { $this->exif_data = @exif_read_data($this->image->imagePath, 0, true); } // stop here if we didn't need other meta data if ($onlyEXIF) { return true; } // get the iptc data - should be in APP13 if (is_callable('iptcparse') && isset($metadata['APP13'])) { $this->iptc_data = @iptcparse($metadata['APP13']); } // get the xmp data in a XML format if (is_callable('xml_parser_create')) { $this->xmp_data = $this->extract_XMP($this->image->imagePath); } return true; } return false; }
/** * 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); if (function_exists("mb_detect_encoding") && mb_detect_encoding($word) != "UTF-8") { $word = utf8_encode($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; }
/** * returns informations from IPTC metadata, mapping is done in this function. * * @param string $filename * @param array $map * @return array */ function get_iptc_data($filename, $map, $array_sep = ',') { global $conf; $result = array(); $imginfo = array(); if (false == @getimagesize($filename, $imginfo)) { return $result; } if (isset($imginfo['APP13'])) { $iptc = iptcparse($imginfo['APP13']); if (is_array($iptc)) { $rmap = array_flip($map); foreach (array_keys($rmap) as $iptc_key) { if (isset($iptc[$iptc_key][0])) { if ($iptc_key == '2#025') { $value = implode($array_sep, array_map('clean_iptc_value', $iptc[$iptc_key])); } else { $value = clean_iptc_value($iptc[$iptc_key][0]); } foreach (array_keys($map, $iptc_key) as $pwg_key) { $result[$pwg_key] = $value; if (!$conf['allow_html_in_metadata']) { // in case the origin of the photo is unsecure (user upload), we // remove HTML tags to avoid XSS (malicious execution of // javascript) $result[$pwg_key] = strip_tags($result[$pwg_key]); } } } } } } return $result; }
/** * Parse the iptc info and retrive the given value. * * Ref. http://codex.wordpress.org/Function_Reference/wp_read_image_metadata#Parameters * WP already adds some IPTC data * * @param $value The item you want returned * @param $image The image you want info from */ public function iptcParser($value = null, $image = null) { $size = getimagesize($image, $info); if (!isset($info['APP13'])) { return; } $iptc = iptcparse($info['APP13']); switch ($value) { case 'keywords': if (isset($iptc['2#025'])) { return $iptc['2#025']; } case 'city': if (isset($iptc['2#090'][0])) { return $iptc['2#090'][0]; } case 'region': if (isset($iptc['2#095'][0])) { return $iptc['2#095'][0]; } case 'country': if (isset($iptc['2#101'][0])) { return $iptc['2#101'][0]; } default: return false; } }
/** * Parses the nggMeta data only if needed * @param int $image path to a image * @param bool $onlyEXIF parse only exif if needed * @return */ function __construct($image_or_id, $onlyEXIF = false) { if (is_int($image_or_id)) { //get the path and other data about the image $this->image = C_Image_Mapper::get_instance()->find($image_or_id); } else { $this->image = $image_or_id; } $imagePath = C_Gallery_Storage::get_instance()->get_image_abspath($this->image); if (!file_exists($imagePath)) { return false; } $this->size = @getimagesize($imagePath, $metadata); if ($this->size && is_array($metadata)) { // get exif - data if (is_callable('exif_read_data')) { $this->exif_data = @exif_read_data($imagePath, NULL, TRUE); } // stop here if we didn't need other meta data if ($onlyEXIF) { return true; } // get the iptc data - should be in APP13 if (is_callable('iptcparse') && isset($metadata['APP13'])) { $this->iptc_data = @iptcparse($metadata['APP13']); } // get the xmp data in a XML format if (is_callable('xml_parser_create')) { $this->xmp_data = $this->extract_XMP($imagePath); } return true; } return false; }
public static function parseImage($filename) { if (@getimagesize($filename, $data) && isset($data['APP13'])) { return self::translateKeys(iptcparse($data['APP13'])); } return null; }
/** * nggMeta::nggMeta() * * @param string $image path to a image * @param bool $onlyEXIF parse only exif if needed * @return */ function nggMeta($image, $onlyEXIF = false) { $this->imagePath = $image; if (!file_exists($this->imagePath)) { return false; } $size = @getimagesize($this->imagePath, $metadata); if ($size && is_array($metadata)) { // get exif - data if (is_callable('exif_read_data')) { $this->exif_data = @exif_read_data($this->imagePath, 0, true); } // stop here if we didn't need other meta data if ($onlyEXIF) { return true; } // get the iptc data - should be in APP13 if (is_callable('iptcparse')) { $this->iptc_data = @iptcparse($metadata["APP13"]); } // get the xmp data in a XML format if (is_callable('xml_parser_create')) { $this->xmp_data = $this->extract_XMP($this->imagePath); } return true; } return false; }
/** * 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); if (function_exists("mb_detect_encoding") && mb_detect_encoding($tag) != "UTF-8") { $tag = utf8_encode($tag); } $tags[$tag] = 1; } } } } // @todo figure out how to read the keywords from xmp foreach (array_keys($tags) as $tag) { tag::add($photo, $tag); } return; }
public function parseIPTC() { $aArr = @exif_read_data($this->sFilename, 'IDF0', true); $size = getimagesize($this->sFilename, $info); if (!isset($info['APP13'])) { return false; } $iptc = iptcparse($info['APP13']); if (isset($iptc["2#120"][0])) { # caption $this->aAttributes['title'] = trim($iptc["2#120"][0]); } else { if (isset($iptc["2#105"][0])) { # headline $this->aAttributes['title'] = trim($iptc["2#105"][0]); } else { if (isset($iptc["2#005"][0])) { # graphic name $this->aAttributes['title'] = trim($iptc["2#005"][0]); } } } if (isset($iptc["2#055"][0]) && isset($iptc["2#060"][0])) { # creation date $iTimestamp = self::timestampFromIPTC($iptc["2#055"][0], $iptc["2#060"][0]); if ($iTimestamp !== false) { $this->aAttributes['datetime'] = $iTimestamp; } } return true; }
function indexJPG(&$page) { global $_XDATA; // $_VDATA; if ($page->intostat == true) { $size = getimagesize($_XDATA['tempfile'], $info); if (isset($info['APP13'])) { $iptc = iptcparse($info["APP13"]); if (is_array($iptc)) { $page->title = isset($iptc["2#005"][0]) ? $iptc["2#005"][0] : ""; $page->body = isset($iptc["2#120"][0]) ? $iptc["2#120"][0] : ""; $page->keywords = isset($iptc["2#025"]) && count($iptc["2#025"]) ? implode(" ", $iptc["2#025"]) : ""; $page->keywords .= isset($iptc["2#020"]) && count($iptc["2#020"]) ? " " . implode(" ", $iptc["2#020"]) : ""; $page->title = preg_replace("/[^a-z0-9\\-\\/\"'(),.:;!\$& *%#~+=_?]/i", "", $page->title); $page->body = $page->description = preg_replace("/[^a-z0-9\\-\\/\"'(),.:;!\$& *%#~+=_?]/i", "", $page->body); $page->keywords = preg_replace("/[^a-z0-9\\-\\/\"'(),.:;!\$& *%#~+=_?]/i", "", $page->keywords); if ($GLOBALS['VDATA']['sp.utf8'] == "true") { $page->body = utf8_encode($page->body); $page->title = utf8_encode($page->title); $page->description = utf8_encode($page->description); $page->keywords = utf8_encode($page->keywords); } return 1; } } } else { return -1; } return 0; }
public function iptc($filename) { $size = getimagesize($filename, $info); if (isset($info["APP13"])) { $this->_metadata = iptcparse($info["APP13"]); } $this->_file = $filename; }
private function checkIptc() { getimagesize($this->_filename, $info); if (isset($info['APP13'])) { $this->_meta = iptcparse($info['APP13']); return true; } }
public function __construct($file) { if (!(file_exists($file) && is_readable($file))) { throw new FileReadException(sprintf('file %s in not readable', $file)); } getimagesize($file, $this->iptc); $this->iptc_app13 = @iptcparse($this->iptc['APP13']); }
/** * Creates a segment instance * * @param string $marker * @param string $bytes * @return self */ public static function read($marker, $bytes) { if (is_array($iptc = iptcparse($bytes))) { return XPClass::forName('img.io.IptcSegment')->newInstance($marker, $iptc); } else { return new self($marker, $bytes); } }
function __construct($filename) { $info = null; $size = getimagesize($filename, $info); if (isset($info["APP13"])) { $this->meta = iptcparse($info["APP13"]); } $this->file = $filename; }
function iptc($filename) { $size = getimagesize($filename, $info); $this->hasmeta = isset($info["APP13"]); if ($this->hasmeta) { $this->meta = iptcparse($info["APP13"]); } $this->file = $filename; }
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]]; if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { $value = utf8_encode($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]); if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { $value = utf8_encode($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(); }
/** * Constructor * * @param string * The name of the image file to access and extract IPTC information from. * * @access public */ function Image_IPTC($sFilename) { $this->_sFilename = $sFilename; if (is_file($this->_sFilename)) { if (@getimagesize($this->_sFilename, $aAPP) && !empty($aAPP)) { $this->_aIPTC = @iptcparse($aAPP['APP13']); $this->_bIPTCParse = true; } } }
static function extract($item) { $keys = array(); // Only try to extract IPTC from photos if ($item->is_photo() && $item->mime_type == "image/jpeg") { $info = getJpegHeader($item->file_path()); if ($info !== FALSE) { $iptcBlock = getIptcBlock($info); if ($iptcBlock !== FALSE) { $iptc = iptcparse($iptcBlock); } else { $iptc = array(); } $xmp = getXmpDom($info); foreach (self::keys() as $keyword => $iptcvar) { $iptc_key = $iptcvar[0]; $xpath = $iptcvar[2]; $value = null; if ($xpath != null) { $value = getXmpValue($xmp, $xpath); } if ($value == null) { if (!empty($iptc[$iptc_key])) { $value = implode(";", $iptc[$iptc_key]); if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { $value = utf8_encode($value); } } } if ($value != null) { $keys[$keyword] = Input::clean($value); } } } } $record = ORM::factory("iptc_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(); if (array_key_exists('Keywords', $keys)) { $tags = explode(';', $keys['Keywords']); foreach ($tags as $tag) { try { tag::add($item, $tag); } catch (Exception $e) { Kohana_Log::add("error", "Error adding tag: {$tag}\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); } } } }
function getid3_jpg(&$fd, &$ThisFileInfo) { $ThisFileInfo['fileformat'] = 'jpg'; $ThisFileInfo['video']['dataformat'] = 'jpg'; $ThisFileInfo['video']['lossless'] = false; $ThisFileInfo['video']['bits_per_sample'] = 24; $ThisFileInfo['video']['pixel_aspect_ratio'] = (double) 1; fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $imageinfo = array(); list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($fd, $ThisFileInfo['filesize']), $imageinfo); if (isset($imageinfo['APP13'])) { // http://php.net/iptcparse // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html $iptc_parsed = iptcparse($imageinfo['APP13']); if (is_array($iptc_parsed)) { foreach ($iptc_parsed as $iptc_key_raw => $iptc_values) { list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw); $iptc_tagkey = intval(ltrim($iptc_tagkey, '0')); foreach ($iptc_values as $key => $value) { @($ThisFileInfo['iptc'][$this->IPTCrecordName($iptc_record)][$this->IPTCrecordTagName($iptc_record, $iptc_tagkey)][] = $value); } } } //echo '<pre>'.htmlentities(print_r($iptc_parsed, true)).'</pre>'; } switch ($type) { case 2: // JPEG $ThisFileInfo['video']['resolution_x'] = $width; $ThisFileInfo['video']['resolution_y'] = $height; if (version_compare(phpversion(), '4.2.0', '>=')) { if (function_exists('exif_read_data')) { ob_start(); $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false); $errors = ob_get_contents(); if ($errors) { $ThisFileInfo['warning'][] = strip_tags($errors); unset($ThisFileInfo['jpg']['exif']); } ob_end_clean(); } else { $ThisFileInfo['warning'][] = 'EXIF parsing only available when ' . (GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif'); } } else { $ThisFileInfo['warning'][] = 'EXIF parsing only available in PHP v4.2.0 and higher compiled with --enable-exif (or php_exif.dll enabled for Windows). You are using PHP v' . phpversion(); } return true; break; default: break; } unset($ThisFileInfo['fileformat']); return false; }
public function getMeta() { $info = array(); $size = getimagesize($this->path . $this->filename, $info); if (isset($info['APP13'])) { $app13 = $info['APP13']; $iptcUnhandled = iptcparse($app13); $returnIPTCarray = $this->getIPTC($iptcUnhandled); print_r($returnIPTCarray); } }
/** * Parses IPTC data for a given file * * @param string $filename Path of file to be parsed * @return array IPTC data or null if none existing */ public function parseIptcData($filename) { if (function_exists('iptcparse')) { getimagesize($filename, $info); if (is_array($info)) { $iptc = iptcparse($info["APP13"]); return $iptc; } } return null; }
public function __construct($filename) { $this->path = $filename; // echo 'IPTC Loading for: '.$filename.'<br />'; $size = getimagesize($filename, $info); $this->hasmeta = isset($info["APP13"]); if ($this->hasmeta) { $this->meta = iptcparse($info["APP13"]); } // print_r($this->meta); $this->file = $filename; }
function getIptc() { $iptc_metadata = array(); $iptc_table['2#005'] = 'iptc_object_name'; $iptc_table['2#015'] = 'iptc_category'; $iptc_table['2#020'] = 'iptc_supplemental_category'; $iptc_table['2#025'] = 'iptc_keywords'; $iptc_table['2#055'] = 'iptc_date_created'; $iptc_table['2#060'] = 'iptc_time_created'; $iptc_table['2#062'] = 'iptc_digital_creation_date'; $iptc_table['2#063'] = 'iptc_digital_creation_time'; $iptc_table['2#065'] = 'iptc_originating_program'; $iptc_table['2#070'] = 'iptc_program_version'; $iptc_table['2#080'] = 'iptc_by_line'; $iptc_table['2#085'] = 'iptc_by_line_title'; $iptc_table['2#090'] = 'iptc_city'; $iptc_table['2#092'] = 'iptc_sub_location'; $iptc_table['2#095'] = 'iptc_province_state'; $iptc_table['2#100'] = 'iptc_country_primary_location_code'; $iptc_table['2#101'] = 'iptc_country_primary_location_name'; $iptc_table['2#105'] = 'iptc_headline'; $iptc_table['2#110'] = 'iptc_credit'; $iptc_table['2#115'] = 'iptc_source'; $iptc_table['2#116'] = 'iptc_copyright_notice'; $iptc_table['2#118'] = 'iptc_contact'; $iptc_table['2#120'] = 'iptc_caption_abstract'; $iptc_table['2#122'] = 'iptc_caption_writer'; $iptc_table['2#131'] = 'iptc_image_orientation'; $size = getimagesize($this->filepath, $info); if (is_array($info) && isset($info["APP13"])) { $iptc = iptcparse($info["APP13"]); if (is_array($iptc)) { foreach (array_keys($iptc) as $k) { foreach ($iptc[$k] as $val) { if (isset($iptc_table[$k]) && $val) { //NOTE THAT REPEAT FIELDS ARE OK!!!!!!!!!!! $iptc_metadata[$iptc_table[$k]][] = $val; } } } } } foreach ($iptc_metadata as $k => $v) { //collapse multiples into a csv $this->metadata[$k] = join(',', $v); //keep having copyright symbol crashes if (strpos($this->metadata[$k], " ©")) { $this->metadata[$k] = str_replace(" ©", ' copyright', $this->metadata[$k]); } } return $iptc_metadata; }
function get_IPTC($filename) { $size = GetImageSize($filename, $info); if (isset($info["APP13"])) { $iptc = iptcparse($info["APP13"]); if (is_array($iptc)) { $IPTC_data = array("Title" => $iptc["2#005"][0], "Urgency" => $iptc["2#010"][0], "Category" => $iptc["2#015"][0], "SubCategories" => $iptc["2#020"], "Keywords" => $iptc["2#025"], "Instructions" => $iptc["2#040"][0], "CreationDate" => $iptc["2#055"][0], "CreationTime" => $iptc["2#060"][0], "ProgramUsed" => $iptc["2#065"][0], "Author" => $iptc["2#080"][0], "Position" => $iptc["2#085"][0], "City" => $iptc["2#090"][0], "State" => $iptc["2#095"][0], "Country" => $iptc["2#101"][0], "TransmissionReference" => $iptc["2#103"][0], "Headline" => $iptc["2#105"][0], "Credit" => $iptc["2#110"][0], "Source" => $iptc["2#115"][0], "Copyright" => $iptc["2#116"][0], "Caption" => $iptc["2#120"][0], "CaptionWriter" => $iptc["2#122"][0]); } else { $IPTC_data = array(); } } return $IPTC_data; }
public static function processIptc($img, $node = 'iptc') { getimagesize($img, $info); $node = new XMLElement($node); if (isset($info['APP13'])) { $iptc = iptcparse($info['APP13']); foreach ($iptc as $handle => $val) { $tag = self::iptcHandle($handle); $temp = new XMLElement('data', self::clean($val), array('tag' => $tag, 'handle' => $handle)); $node->appendChild($temp); } } return $node; }
public static function getAsJson($file, $force = false) { $json = array(); getimagesize($file, $info); if (isset($info["APP13"])) { $iptc = iptcparse($info["APP13"]); if (isset($iptc['2#120'])) { $caption = implode('|', $iptc['2#120']); // nb: '|' should never actually appear $caption = ensureUTF8($caption); // since could be 'local' encoding $caption = mysql_escape_string($caption); // safety. stackoverflow.com/q/1162491 $json['caption'] = $caption; } if (isset($iptc['2#025'])) { $json['keywords'] = $iptc['2#025']; } // keep as array set_error_handler("ignoreAnyError", E_ALL); // TOTEST, currently no exif enabled on localhost if (function_exists('exif_read_data')) { $json['exif'] = exif_read_data($tmpfile, 0, false); } // fails on a very few files (corrupt EXIF) restore_error_handler(); } Log::info("json for :" . $file); Log::info($json); return $json; }