I am in the proces of writing a Joomla extension that utilizes metadata embedded in image files in IPTC, EXIF and XMP chunks. In particular, I want to gain access to "Title", "Tags", "Date Taken" and "GPS coordinates". The code embedded below is written by Lukáš Řádek and appears in https://stackoverflow.com/questions/1578169/how-can-i-read-xmp-data-from-a-jpg-with-php
<?php
libxml_use_internal_errors(true);
function getXmpData($filename, $chunk_size = 50000) {
$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;
}
$xmp_data = getXmpData('test.jpg',1024);
$xmp = simplexml_load_string($xmp_data);
if ($xmp === false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
$mystring = $xmp->asXML();
echo "$mystring\n";
?>
It works like a charm but it would be hard to use in a general Joomla-extension because such an extension would have to address older as well as coming industry standards for image metadata encoding. Of course you cannot predict future standards but you can make life easier on yourself by utilizing packages/toolkits maintained by others ("Off-the-shelf-products"). Such a toolkit by Adobe is mentioned in Wikipedia: Extensible Metadata Platform but none of the implementations are in PHP.
Question 1) This where my skillset reaches its limit. Surely, there must be ways to compile such a toolset from Adobe into a format where it can be invoked from PHP? Please advise.
Question 2) I know how to build Joomla-extension packages using PHP/HTML/CSS/Javascript/Mysql and to implement MVC architecture etc. thanks to the wonderful lessons at Developing an MVC Component but how would you include the solution from Question 1) into a Joomla extension and make it executable on Linux as well as. Windows web hotels? I can live with the exclusion of Windows. If not possible at all - see Question 3
Question 3 If not possible to embed 3rd party compiled code in Joomla extensions, would you consider the possibility of installing compiled libraries on general web hosting servers and making them available to PHP/Joomla?
Sometimes it is harder to phrase the question than to find the answer. If you do not believe me, read the story of "42" in "Hitchikers guide to the Galaxy" :-)
$buffer
, please include that sample data.