Announcement

#1 2018-07-15 21:09:41

ceinmart
Member
2017-08-17
20

trying load exif data with exiftool

Hi,

Until now I added my photos on piwigo importing from flickr where the plugin works great (thanks Sam!) .
Now I'm starting to upload my current photos but the exif data isn't imported.
I check and found the error below is occuring :
 

Warning: read_exif_data(sample.jpg): IFD data bad offset: 0xFFFFFAE6 length 0x1BF6 in /home/imartins/public_html/fotos/tools/teste1.php on line 7

The PHP version is 7.0 and I tried with 7.1 where get the same error .

After install the exiftools binary on my server I've tested with it and works very well, read all exif information from my photos without any problem.
QUESTION 1: I would to know if is possible to replace the PHP function "read_exif_data" to "exiftools" easily without edit the piwigo sources.

I'm not PHP developer but I was developer before and read/understand PHP isn't anything that hard...
So,I trying adapt the plugin exiftool_keywords to do the job.  With my changes I'm able to load the basic exif data but is failing with the keywords/tags .

QUESTION 2: What I'm doing wrong here :

1. I add this code at my config.inc.php :

Code:

// for exiftools_keywords works, need to set this exif_mapping, otherwise the $exif[] is ignored.
$conf['use_exif_mapping'] = array(
  'Keywords'      => 'Keywords',
  'date_creation' => 'date_creation',
  'name'          => 'name',
  'comment'       => 'comment',
  'author'        => 'author',
  'rating_score'  => 'rating_score',
);
// need active this to avoid the error :  PHP Warning:  strip_tags() expects parameter 1 to be string, array given in /home/imartins/public_html/fotos/include/functions_metadata.inc.php on line 205
$conf['allow_html_in_metadata'] = true;

2. I changed the main.inc.php from exiftool_keyword plugin where I add the lines below :

Code:

  error_log('metadata...' );
  error_log(print_r($metadata[0],true) );
   if (isset($metadata[0]['XPKeywords'])) { $exif['Keywords'] = $metadata[0]['XPKeywords']; }
   if (isset($metadata[0]['Keywords']   )) { $exif['Keywords']         = implode(',',$metadata[0]['Keywords'])         ;};
 //if (isset($metadata[0]['Keywords']   )) { $exif['Keywords']         = $metadata[0]['Keywords']         ;};
   if (isset($metadata[0]['CreateDate'] )) { $exif['date_creation']    = $metadata[0]['CreateDate']       ;};
   if (isset($metadata[0]['Description'])) { $exif['name']             = $metadata[0]['Description']      ;};
   if (isset($metadata[0]['UserComment'])) { $exif['comment']          = $metadata[0]['Description']      ;};
   if (isset($metadata[0]['Artist']     )) { $exif['author']           = $metadata[0]['Artist']           ;};
   if (isset($metadata[0]['Rating']     )) { $exif['rating_score']     = $metadata[0]['Rating']           ;};
  error_log('exif...' );
  error_log(print_r($exif,true) );

The "keywords" key is an array at metadata[0].
If I keep it as array, at the import, got the error "PHP Warning:  strip_tags() expects parameter 1 to be string".
Then I check the source and enabled the parameter "allow_html_in_metadata" to ignore the "strip_tags" call.
After that the error changed to :

Code:

   [15-Jul-2018 18:34:40 UTC] PHP Warning:  addslashes() expects parameter 1 to be string, array given in /home/imartins/public_html/fotos/admin/include/functions_metadata.php on line 122

So, I decide to "revert" the keyword to an string with comma as separator, then I use the "implode" PHP function for that.
But then I stop at the error below where the piwigo try to update it as a "regular" exif key....

Code:

[15-Jul-2018 18:28:12 UTC] PHP Warning:  [mysql error 1054] Unknown column 'Keywords' in 'field list'

UPDATE piwigo_images
  SET filesize = '892',
    width = '1600',
    height = '1067',
    Keywords = 'animais,arvores,brasil,minas gerais,monte sião,praça',

Any tips?



Piwigo 2.9.3
Operating system: Linux
PHP: 7.0.30 (Show info) [2018-07-15 19:03:51]
MySQL: 5.5.5-10.1.31-MariaDB-cll-lve [2018-07-15 16:03:51]
Graphics Library: External ImageMagick 6.7.8-9
Piwigo URL: http://fotos.imartins.com.br

Last edited by ceinmart (2018-07-17 00:03:12)

Offline

 

#2 2018-07-17 05:47:09

executive
Member
2017-08-16
1214

Re: trying load exif data with exiftool

That looks like a lot of work. Why not just enable the exif module in PHP?


https://piwigo.org/forum/viewtopic.php?id=28047
https://piwigo.org/forum/viewtopic.php? … 25#p167725

Last edited by executive (2018-07-17 06:00:06)

Offline

 

#3 2018-07-20 01:14:43

ceinmart
Member
2017-08-17
20

Re: trying load exif data with exiftool

Hi @executive ,
Thank you for the tip.
I didn't try the ImageMagic GPS because I believe on the title...only for GPS :)
Before I installed the exiftools GPS plugin, but it have treatment for GPS data only, so I didn't tried the ImageMagic...

Anyway, I will check this plugin too , I'll hope for they do more then what they promise...

Offline

 

#4 2018-07-29 22:19:21

ceinmart
Member
2017-08-17
20

Re: trying load exif data with exiftool

Hi all,

I tried use the ImageMagic plugin , where I able to active it successfully , but even with it I still get the error "IFD data bad offset" .

So, any one which understand the piwigo source can help me how to make my "fix" to workaround works ?

I'm still unable to load the keywords from the exif using exiftool command.

You can check a sample of the error at : https://fotos.imartins.com.br/tools/teste1.php
with this source:

Code:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

$filename='sample.jpg' ; 
echo 'EXIF Fields in '.$filename.'<br>';
$exif = read_exif_data($filename);
echo '<pre>';
print_r($exif);

echo '============ exiftool' ; 
echo '</br>' ; 
echo '</br>' ; 
//$output = shell_exec('/home/imartins/public_html/fotos/exiftool -json "'.$filename.'"');
$output = shell_exec('/home/imartins/bin/exiftool -json "'.$filename.'"');
print_r($output);
echo '</br> ---' ; 
$metadata = json_decode($output, true);
print_r($metadata);
echo '</pre>';
?>

Thank you!
Regards
Cesar

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact