Announcement

  •  » Extensions
  •  » Lightroom star rating import

#1 2019-03-23 09:17:12

executive
Member
2017-08-16
1214

Lightroom star rating import

I want to develop a way to bring the star ratings from Adobe Lightroom into Piwigo. I haven't decided yet if I want to convert the ratings into generic keywords, or if I can integrate it into the existing Piwigo rating system.

The rating is stored as an integer value in the "rating" field. This field is part of the embedded XMP metadata. XMP (Extensible Metadata Platform) is an open metadata standard publish by Adobe in 2012, and seems to be the successor to IPTC.

So far (using tools/metadata.php), I'm not able to read XMP data in Piwigo.  Exiftool does read/write XMP data.
ImageMagick is able to read XMP data (but not write):

ImageMagick command:

Code:

convert -ping sample-rating.jpg xmp:-

<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 11.11'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

 <rdf:Description rdf:about=''
  xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
  <xmp:Rating>3</xmp:Rating>
 </rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?>

More investigation needed ...
Anyway, before I dive too deep into it, I wanted to reach out to see if anybody else has attempted it, or if maybe some code already exists.

Cheers.

Last edited by executive (2019-03-23 11:57:10)

Offline

 

#2 2019-03-23 22:33:38

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

The [extension by grum] Advanced Metadata claims to read XMP metadata.
Unfortunately, it's 7 years old now and incompatible with Piwigo >2.4
I tried copied it to Piwigo anyway, but was unable to activate it:

Parse error: Invalid numeric literal in ........./plugins/AMetaData/JpegMetaData/TagDefinitions/IptcTags.class.php on line 2184
which is

Code:

static function attributesLabel($attributeCode)
    {
      if(is_string($attributeCode))
      {
        @$attributeCode=(int)$attributeCode;
      }

      switch($attributeCode)
      {
        case 001: $returned="Current"; break;
        case 002: $returned="Analysis"; break;
        case 003: $returned="Archive material"; break;
        case 004: $returned="Background"; break;
        case 005: $returned="Feature"; break;
        case 006: $returned="Forecast"; break;
        case 007: $returned="History"; break;
>        case 008: $returned="Obituary"; break;
        case 009: $returned="Opinion"; break;
        case 010: $returned="Polls & Surveys"; break;
        case 011: $returned="Profile"; break;
        case 012: $returned="Results Listings & Tables"; break;
        case 013: $returned="Side bar & Supporting information"; break;
        case 014: $returned="Summary"; break;
        case 015: $returned="Transcript & Verbatim"; break;
        case 016: $returned="Interview"; break;
        case 017: $returned="From the Scene"; break;
        case 018: $returned="Retrospective"; break;
        case 019: $returned="Statistics"; break;
        case 020: $returned="Update"; break;
        case 021: $returned="Wrap-up"; break;
        case 022: $returned="Press Release"; break;
        default:
          $returned="unknown code ".$attributeCode;
          break;
      }
      return($returned);
    }

Last edited by executive (2019-03-23 22:40:35)

Offline

 

#3 2019-03-23 22:44:34

erAck
Only trying to help
2015-09-06
1998

Re: Lightroom star rating import

My mere assumption: numeric values with leading zero are treated as octal numbers, where 008 is invalid. Try to remove all leading 0s.


Running Piwigo at https://erack.net/gallery/

Offline

 

#4 2019-03-23 23:21:04

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

Cool. Removed the leading zeros. I'm getting warnings, but the plugin activated.

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; StringReader has a deprecated constructor in .../plugins/AMetaData/JpegMetaData/External/php-gettext/streams.php on line 48

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; FileReader has a deprecated constructor in .../plugins/AMetaData/JpegMetaData/External/php-gettext/streams.php on line 84

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; CachedFileReader has a deprecated constructor in .../plugins/AMetaData/JpegMetaData/External/php-gettext/streams.php on line 145

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; gettext_reader has a deprecated constructor in .../plugins/AMetaData/JpegMetaData/External/php-gettext/gettext.php on line 36

Warning: Cannot modify header information - headers already sent by (output started at .../plugins/AMetaData/JpegMetaData/External/php-gettext/streams.php:48) in .../include/page_header.php on line 101

Last edited by executive (2019-03-23 23:22:02)

Offline

 

#5 2019-03-23 23:28:20

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

I switched the plugin to advanced mode to see all the metadata, but now I get an error.

Fatal error: Uncaught Error: Call to undefined function trigger_action() in .../plugins/AMetaData/amd_pip.class.inc.php:97 Stack trace: #0 .../include/functions_plugins.inc.php(279): AMD_PIP->loadMetadata() #1 .../picture.php(152): trigger_notify('loc_begin_pictu...') #2 {main} thrown in .../plugins/AMetaData/amd_pip.class.inc.php on line 97

Code:

    trigger_action('amd_jpegMD_loaded', $this->jpegMD);

Offline

 

#6 2019-03-24 01:13:05

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

The plugin includes a test PHP page, and it was able to display the XMP rating tag in my test image.

Just skimming through the code, it looks like the process is low level. It doesn't leverage PHP functions or extensions. Wrangling this complex code looks tricky.

Last edited by executive (2019-03-24 01:15:18)

Offline

 

#7 2019-03-25 11:56:26

eliz82
Member
Romania
2016-04-27
281

Re: Lightroom star rating import

if you have exiftool installed on you webserver importing xmp data to piwigo keywords should be an easy task

inject data from exiftool output to piwigo exif data array
https://piwigo.org/forum/viewtopic.php? … 79#p169579

you need to modify my example for the exiftool command line to read the xmp
https://stackoverflow.com/a/26976859/4481831

then import the data from exif to tags/keywords using the normal method
http://piwigo.org/forum/viewtopic.php?id=28203

if you provide some sample image that has xmp rating i can try to run some tests

Last edited by eliz82 (2019-03-25 11:57:12)

Offline

 

#8 2019-03-25 19:56:08

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

I don't think my hosting package allows exec calls, but I'll try it out. Thanks.


Here is a sample image.

Offline

 

#9 2019-03-25 23:43:48

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

I discovered that I have the ability to enable shell_exec by enabling all functions in php.ini (disable_functions = "").
I was able to display the output of exiftool in a test PHP script.
However, doing this seems like a bad idea.

Offline

 

#10 2019-03-26 11:18:37

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

I've made some good progress.

I definitely won't be going the exiftool route. It is unsecure and unnecessary.

Method 1: ImageMagick
$someArray = imagick("/path/to/example.jpg")->getImageProperties("xmp:*");
Seems to be really easy and straighforward. Tested. Works for Rating, but does not support some XMP values.

Method 2: Manual
Manually read in the XMP data (which is in plain text.) using file_get_contents() or fopen() .
XML data can then made into an XML object using SimpleXML
XML children are parsed using public namespace URIs
Tested. Works. More complicated.

Method 3: Evan Hunter's PHP toolkit
http://www.ozhiker.com/electronics/pjmt/
Not tested yet.

Adobe has an XMP toolkit, but I think it's Java/C++ only.

Many more options still untested
https://en.wikipedia.org/wiki/Extensibl … e_support)

Offline

 

#11 2019-04-01 19:49:18

eliz82
Member
Romania
2016-04-27
281

Re: Lightroom star rating import

I had some free time today and made some tests based on my previous post

personal plugin

Code:

add_event_handler('format_exif_data', 'ir_format_exif_data');

function ir_format_exif_data($exif, $filepath) {
  if (!function_exists('shell_exec')) { //check if function is not available
    die('shell_exec is disabled. check php.ini');
  }
  $output = shell_exec('exiftool -g -json -xmp:all "'.$filepath.'"'); //execute external and get the response to variable
  $exiftool_metadata = json_decode($output, true); //convert json to array
  if (isset($exiftool_metadata[0]['XMP'])) { //if XMP data exist
    $exif['XMP'] = $exiftool_metadata[0]['XMP']; //add exiftool_exif to php_exif
  }
  //print('<pre>'.print_r($exif,true).'</pre>'); //debug, help for exif configuration
  return $exif;
}

local config

Code:

$conf['show_exif_fields'] = array(
  'Make',
  'Model',
  'DateTimeOriginal',
  'COMPUTED;ApertureFNumber',
  'XMP;Rating'
  );

$lang['exif_field_Rating'] = 'XMP Rating'; //demo how to change a field name

$conf['use_exif_mapping'] = array(
  'date_creation'        => 'DateTimeOriginal',
  'tags'                 => 'XMP;Rating'
  );

the xmp rating was successfully displayed and imported as tags (when upload or re-sync)

Offline

 

#12 2019-04-01 20:18:46

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

Nice.

I've been working on a new plugin that uses imagemagick.

Last edited by executive (2019-04-01 20:21:12)

Offline

 

#13 2019-09-02 10:46:46

dmfisch
Member
Geneva
2019-09-02
12

Re: Lightroom star rating import

Hello,

I discovered Piwigo recently and installed it last night

Thank You for your interest with this rating issue.
I am also really interested by this feature, i am unable to do coding, but am available to do testing and provide logs.

Furthermore, as I am doing a photo library for my photo professionnal activity, I gladly made a donation to Piwigo, and will be happy to hire someone's time and pay to develop a plugin everyone could use.

My wish is get the XMP star rating to somehow appear in the keywords, I need viewers to use my rating to help their searches, but I dont' need it to be managed by piwigo voting/rating system.

Thank You very much!

David

Last edited by dmfisch (2019-09-02 10:48:26)


Photographer
No coding skills but willing to help and test!

Offline

 

#14 2019-09-02 18:45:50

dmfisch
Member
Geneva
2019-09-02
12

Re: Lightroom star rating import

I am thinking about the star keyword, would it be possible to compose "keyword" with 1, 2, 3, 4, 5 star symbols  using Unicode number U+2605 or the other code according to the "language"?

Encoding
HTML Entity    ★   
HTML Entity (hex)    &#x2605;   
HTML Entity (named)    ★   
URL Escape Code    %E2%98%85   
UTF-8 (hex)    0xE2 0x98 0x85   
UTF-8 (binary)    11100010:10011000:10000101   
UTF-16    0x2605   
UTF-32    0x00002605   
Source Code
C, C++, and Java    "\u2605"   
CSS Code    \2605   
JavaScript    "\u2605"   
Perl    \x{2605}   
Python 2    u"\u2605"   
Python 3    \u2605   
Ruby    \u{2605}


Photographer
No coding skills but willing to help and test!

Offline

 

#15 2019-09-02 21:03:26

executive
Member
2017-08-16
1214

Re: Lightroom star rating import

I will take it into consideration. This is a hobby thing that I do in my spare time (rare) and my coding skills are weak, so I can't promise anything soon.

Offline

 
  •  » Extensions
  •  » Lightroom star rating import

Board footer

Powered by FluxBB

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