Thank you Mike.
Also I have another mod to have TWG read keywords from PDF and it works ok so far. In case it may be useful, please feel free to modify the code.
readxml.inc.phpCode:
function get_iptc_data($twg_album, $image, $iptc_array, $stOnly = false)
//mod by Pumin
{
global $basedir, $use_iptc_tags, $charset, $iptc_encoding, $iptc_fields_for_imagetags;
$keywords = null;
if ($use_iptc_tags) {
$remote_image = twg_checkurl($basedir . "/" . $twg_album);
if ($remote_image) {
$filename = getRemoteImagePath($remote_image, $image);
} else {
$filename = $basedir . "/" . $twg_album . "/" . $image;
}
$offp = getExtension($image);
if ($offp != 'pdf' ) {
set_error_handler("on_error_no_output"); // images with errors are ignored
$oldsize = @getimagesize($filename, $info);
set_error_handler("on_error");
if (isset($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
if (is_array($iptc)) {
foreach ($iptc_array as $key) {
if (isset($iptc[$key])) {
$keywordcount = count($iptc[$key]);
for ($i = 0; $i < $keywordcount; $i++) $keywords .= $iptc[$key][$i] . ",";
if ($stOnly) {
break;
}
}
}
}
}
if (isset($keywords)) {
$keywords = substr($keywords, 0, -1);
}
} elseif ($offp == 'pdf' && !$remote_image && $iptc_array == $iptc_fields_for_imagetags) {
$content = getXmpData($filename);
$xmp_data_start = strpos($content, '<dc:subject');
$xmp_data_end = strpos($content, '</dc:subject>');
$xmp_length = $xmp_data_end - $xmp_data_start;
if ($xmp_length > 0) {
$keywords = substr($content, $xmp_data_start, $xmp_length + 13);
$keywords = preg_replace("/<\/rdf:li>\s\s+<rdf:li>/", ",", $keywords);
$keywords = preg_replace("/>\s\s+</", "><", $keywords);
$keywords = strip_tags($keywords);
}
}
}
if (isset($charset) && strtolower($charset) == "utf-8" && $iptc_encoding != 'utf-8') {
$keywords = utf8_encode($keywords);
}
return $keywords;
}
function getXmpData($filename, $chunk_size = 50000){
//credit to Bryan Geraghty, Sebastien B. & Lukáš Řádek @stackoverflow.com
$buffer = NULL;
if (($file_pointer = fopen($filename, 'r')) === FALSE) {
throw new RuntimeException('Could not open file for reading');
}
$chunk = fread($file_pointer, $chunk_size);
if (($posStart = strpos($chunk, '<x:xmpmeta')) !== FALSE) {
$buffer = substr($chunk, $posStart);
$posEnd = strpos($buffer, '</x:xmpmeta>');
$buffer = substr($buffer, 0, $posEnd + 12);
}
fclose($file_pointer);
// recursion here
if(!strpos($buffer, '</x:xmpmeta>')){
$buffer = getXmpData($filename, $chunk_size*2);
}
return $buffer;
}