Backlight2 provides the option to access certain image metadata using `Metadata One`, `Metadata Two` and the `Tokens` field. This limits creators who need to access more metadata to provide additional information to the user. Using additional metadata might increase SEO as well.
In this example, I use `Metadata One` which can be found in Backlight > Designer > Album Template > Thumbnail Grid > Metadata Display. Instead of just using a predefined token such as `{Title}: {Caption}`, I combine several metadata tokens using a structured format. For this example I use the string
t1=={t1}||d3=={d3}||filename=={Filename}||Creator=={Creator}||copyright=={Copyright}||keywords=={Keywords}||caption=={Caption}||title=={Title}||aperture=={Aperture}||exposure=={Exposure}||iso=={ISO}||lens=={Lens}||shutterspeed=={ShutterSpeed}
This string is rather long but provides ample of image information. Once you modified it, you have to republish all images! But don’t forget to set ‘Push metadata without updating existing photos’. This can be found by right-clicking on your Lightroom Publisher instance and then selecting “Edit Settings…”. This way, the only metadata are updated which is rather fast.
You can easily identify the format of this string:
token1=={token1}||token2=={token2}||...
I’m naming the metadate tokens in my string to know which data I provided. This makes it more flexible down the road if I want to add one additional token without having to redo all existing code.
In phplugins, I use a function to decode the token/metadata string and create an associative array:
// Splits custom metadata into an associative array
// Metadata string format: name1=={name1}||name2=={name2}||....
// Use metadata string in Backlight Metadata One Token field
// (Backlight>Designer>Album Template>Thumbnail Grid>Metadata Display)
function dlp_extract_custom_metadata($str) {
// Get metadata token pairs
$str_arr = preg_split ("/\|\|/", $str);
// Extract metadata tokens
foreach($str_arr as $i) {
$i_arr = preg_split ("/\=\=/", $i);
$meta[strtolower($i_arr[0])] = $i_arr[1];
}
return $meta;
}
A call to this function will return my metadata as a structured associative array
$meta = $this->dlp_extract_custom_metadata($this->photo->getMetadata("metadata_one"));
Individual tokens are accessed like shown in this example
echo 'Captured: '.$meta['d3'].' at '.$meta['t1'].' by '.$meta['creator'].'<br/>';
Which creates: Captured: September 29, 2019 at 10:39 AM by Daniel Leu
Please note that
- dlp_extract_custom_metadata() doesn’t do any syntax checking. So you better get your token/metadata string right.
- All tokens used in the associative array (‘keys’) are lower case!
- The format assumes that you don’t use ‘||’ and ‘==’ in any of your metadata fields!
To customize the single page view, you use the two phplugins function single_top() and single_bottom(). Here I add some infos to the bottom of the single page view:
function single_bottom() {
// get custom metadata:
$meta = $this->dlp_extract_custom_metadata($this->photo->getMetadata("metadata_one"));
echo '<h2>Showing Custom Metadata</h2>';
// Create a formatted output:
echo 'Title: '.$meta['title'].'<br/>';
echo '---------------------------------------------------<br/>';
echo $meta['caption'].'<br/>';
echo 'Keywords: '.$meta['keywords'].'<br/>';
echo 'Captured: '.$meta['d3'].' at '.$meta['t1'].' by '.$meta['creator'].'<br/>';
echo 'ISO: '.$meta['iso'].' at '.$meta['exposure'].' by '.$meta['shutterspeed'].'<br/>';
echo 'Filename: '.$meta['filename'].'<br/>';
echo $meta['copyright'].'<br/>';
}
While developing your customization, it might be helpful to show all your custom metadata:
function single_bottom() {
// get custom metadata:
$meta = $this->dlp_extract_custom_metadata($this->photo->getMetadata("metadata_one"));
// Display all provided metadata
foreach($meta as $token => $value){
echo $token .': '. $value .'<br/>';
}
}
Happy hacking!
Did you like this post? Did you use the given code? Please consider supporting me by buying me a coffee!
Thanks!
Daniel- thanks for this great tool. A couple of questions on initial set up.
1. You mentioned the location to enter metadata string is in “Gallery Templates” – do you mean Album Templates?
2. The string appears to be entered in the metadata field under Metadata 1 of the thumbnail section – do I leave the selector button on or off for that field? I normally have it off since I don’t add metadata to the thumbnails.
3. On the full image caption field I assume I leave that blank as the phplugin will place data as written?
Thanks
Terry
Hi Terry,
1) yeah, Album Templates
2) off is correct since you don’t want this data to be displayed
3) phplugins will not modify the image caption field, but it provides another way to add information to the single-image page. So you can use the caption field or ignore it.
Hope this helps!
Best
Daniel
thanks – a new tool to play with! Have a great night.