Search…

X3 Photo Gallery Support Forums

Search…
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: Attribute: data-embed-popup-caption-template

13 Oct 2021, 03:38

Ok, so I forgot about the <br> and any formatting. Within the syntax provided, you can easily add your own HTML tags now. For example:
Code
data-embed-popup-caption-template="{{ @if (image.iptc) }}{{ @if (image.iptc.title) }}<strong>{{ image.iptc.title }}</strong>{{/if}}{{ @if (image.iptc.description) }}<br>{{ image.iptc.description }}{{/if}}{{/if}}"
Or if you want to use CSS to style them, wrap them in classes:
Code
data-embed-popup-caption-template="{{ @if (image.iptc) }}{{ @if (image.iptc.title) }}<div class='popup-title'>{{ image.iptc.title }}</div>{{/if}}{{ @if (image.iptc.description) }}<div class='popup-description'>{{ image.iptc.description }}</div>{{/if}}{{/if}}"
Then you can assign styles to CSS classes .popup-title{} and .popup-description{}.
 
traxnamibia
Experienced
Topic Author
Posts: 36
Joined: 17 May 2021, 08:16

Re: Attribute: data-embed-popup-caption-template

13 Oct 2021, 09:46

OK - solved:

data-embed-popup-caption-template="{{ @if (image.iptc) }}{{ @if (image.iptc.title) }}<strong>{{ image.iptc.title }}</strong><br>{{/if}}{{ @if (image.iptc.description) }}{{ image.iptc.description }}{{/if}}{{/if}}"
 
traxnamibia
Experienced
Topic Author
Posts: 36
Joined: 17 May 2021, 08:16

Re: Attribute: data-embed-popup-caption-template

13 Oct 2021, 22:03

Carl - many thanks for your help - I am starting to get my head around how useful and powerful the Embed app is. (also very, very pretty!)

I hope this thread is useful to other users and potential users.

One last question:

You have shown us how to use image.iptc.title and image.iptc.description...

Are there any other IPTC fields that we can use? I know there are a huge number!

I am particularly keen to use Copyright, Creator and Credit Line as they are used by Google Image search:
Image
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: Attribute: data-embed-popup-caption-template

14 Oct 2021, 01:01

traxnamibia wrote:Are there any other IPTC fields that we can use? I know there are a huge number!
Unfortunately no, as additional IPTC data would first have to come from the Files app PHP creates the data for each. Actually, you could bring in more IPTC by editing the function get_iptc($image_info) in Files app. You could add something like this:
Code
if(isset($app13['2#116'][0])) $iptc['copyright'] = safe_iptc_tag($app13['2#116'][0]);
If I am going to add more IPTC fields into Files app and Embed, we will need config options to decide what IPTC fields to look for and how to display them. Here is a list of some IPTC fields and their ID (necessary to extract from PHP):
https://exiftool.org/TagNames/IPTC.html
 
traxnamibia
Experienced
Topic Author
Posts: 36
Joined: 17 May 2021, 08:16

Re: Attribute: data-embed-popup-caption-template

14 Oct 2021, 04:08

OK - I have modified the files app at around line 745 as follows:
Code
function safe_iptc_tag($val, $max_str = 1000){
  $val = @substr($val, 0, $max_str);
  return @mb_detect_encoding($val, 'UTF-8', true) ? $val : @utf8_encode($val);
}

function get_iptc($image_info){
if(!$image_info || !isset($image_info['APP13']) || !function_exists('iptcparse')) return;
$app13 = @iptcparse($image_info['APP13']);
if(empty($app13)) return;
$iptc = array();

  // title // ObjectName
  if(isset($app13['2#005'][0])) $iptc['title'] = safe_iptc_tag($app13['2#005'][0]);

  // description // Caption-Abstract
  if(isset($app13['2#120'][0])) $iptc['description'] = safe_iptc_tag($app13['2#120'][0]);
  
  // copyright // Caption-Abstract
  if(isset($app13['2#116'][0])) $iptc['copyright'] = safe_iptc_tag($app13['2#116'][0]);

  // keywords array
  if(isset($app13['2#025']) && !empty($app13['2#025']) && is_array($app13['2#025'])) {
    $keywords = array_map(function($keyword){
      return safe_iptc_tag($keyword, 100);
    }, $app13['2#025']);
    if(!empty($keywords)) $iptc['keywords'] = $keywords;
  }
return $iptc;
}
and my attribute in my html page https://selfdrive.com.na/photo-embed.html is:
Code
data-embed-popup-caption-template="{{ @if (image.iptc) }}{{ @if (image.iptc.title) }}<div class='popup-title'>{{ image.iptc.title }}</div>{{/if}}{{ @if (image.iptc.copyright) }}<div class='popup-description'>{{ image.iptc.copyright }}</div>{{/if}}{{/if}}"
 and the image map02.jpg definitely does have an embedded Copyright string. See Get Photo Metadata (iptc.org)
but only 'title' is displaying. Effectively, I have just substituted copyright for description in the attribute above.

I hope I have been diligent in applying your code - I don't want this to be a waste of your valuable time while you are coding the new files app!  :-)

Your thoughts?
 
traxnamibia
Experienced
Topic Author
Posts: 36
Joined: 17 May 2021, 08:16

Re: Attribute: data-embed-popup-caption-template

14 Oct 2021, 05:17

If I am going to add more IPTC fields into Files app and Embed, we will need config options to decide what IPTC fields to look for and how to display them
How about adding the 3 fields (creator, credit and copyright) Google search fields as suggested at: Quick guide to IPTC Photo Metadata and Google Images - IPTC

Title:  IPTC IIM 2:05 ["2#005"] title (already included)
Description:  IPTC IIM 2:120 ["2#120"] description (already included)
Creator:  IPTC IIM 2:80 ["2#080"] creator
Credit Line : IPTC IIM 2:110 ["2#110"] credit
Copyright: IPTC IIM 2:116 ["2#116"] copyright

The above 5 fields covers a decent spectrum, I think.
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: Attribute: data-embed-popup-caption-template  Topic is solved

14 Oct 2021, 07:41

traxnamibia wrote:but only 'title' is displaying.
Files/Embed uses a cache system which updates only when the folder gets updated. Editing code in the Files app PHP will not refresh the cache. Thus, it's plausible that the data loaded for the folder (and files) might be cached from before you made the change. You would need to edither 1) Make a change in the dir, for example rename a file, or 2) Increase cache_key option in config, or 3) Disable cache. Option #1 sounds like the easiest option.

Once that's done, refresh page and try again. If no luck, please send me the link so I can check if copyright is loading from the backend (php).
traxnamibia wrote:I hope I have been diligent in applying your code - I don't want this to be a waste of your valuable time while you are coding the new files app!  :-)
Absolutely no problem.
traxnamibia wrote:Title:  IPTC IIM 2:05 ["2#005"] title (already included)
Description:  IPTC IIM 2:120 ["2#120"] description (already included)
Creator:  IPTC IIM 2:80 ["2#080"] creator
Credit Line : IPTC IIM 2:110 ["2#110"] credit
Copyright: IPTC IIM 2:116 ["2#116"] copyright
Yes it might be an option to simply include a few more popular fields like the above. I think someone also request city/location tags ...
 
traxnamibia
Experienced
Topic Author
Posts: 36
Joined: 17 May 2021, 08:16

Re: Attribute: data-embed-popup-caption-template

14 Oct 2021, 10:49

Files/Embed uses a cache system which updates only when the folder gets updated. 
Cache refreshed and all is working perfectly.
The whole cache story not refreshing also explains some of the apparent self-resolving issues yesterday.
I am going to mark this thread as 'solved' - many, many thanks again.

Maybe you want put out a little poll to see which iptc fields users want?
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: Attribute: data-embed-popup-caption-template

14 Oct 2021, 21:21

Great!
traxnamibia wrote:Maybe you want put out a little poll to see which iptc fields users want?
I think I'll just add a handful of additional "core" IPTC fields for now, including the ones you mentioned. I won't render  them into captions (Files/Embed) by default, but they will be available from custom template.

Another option, could be to render all available IPTC fields into captions by default, but hide non-default ones via CSS. Then, instead of using caption-template (slightly tedious), you could unhide IPTC fields via CSS variables, something like --popup-caption-iptc-fieldname: block :thinking:
 
traxnamibia
Experienced
Topic Author
Posts: 36
Joined: 17 May 2021, 08:16

Re: Attribute: data-embed-popup-caption-template

15 Oct 2021, 01:54

The choices seem to be 'six of one, half a dozen of the other'  :thinking: 

I assume when you say 'custom template' you mean data-embed-popup-caption-template which we have been working on the last couple of days? 

Your second option might be more preferable for the simple reason that users will be more familiar with using css than squirrelly's syntax. That's certainly true for me and gets my vote!
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: Attribute: data-embed-popup-caption-template

15 Oct 2021, 04:39

traxnamibia wrote:I assume when you say 'custom template' you mean data-embed-popup-caption-template which we have been working on the last couple of days?
Correct
traxnamibia wrote:Your second option might be more preferable for the simple reason that users will be more familiar with using css than squirrelly's syntax. That's certainly true for me and gets my vote!
Definitely easier with CSS, so I might add it. I will keep caption-template though, because this allows complete control of the caption layout (if needed), whereas CSS would only be hiding/showing/styling existing items via CSS.
 
traxnamibia
Experienced
Topic Author
Posts: 36
Joined: 17 May 2021, 08:16

Re: Attribute: data-embed-popup-caption-template

15 Oct 2021, 08:55

Definitely easier with CSS, so I might add it. I will keep caption-template though, because this allows complete control of the caption layout (if needed), whereas CSS would only be hiding/showing/styling existing items via CSS.
Perfect - I look forward to it! (and the new files app which I assume is not far away now?)
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: Attribute: data-embed-popup-caption-template

15 Oct 2021, 09:55

traxnamibia wrote:(and the new files app which I assume is not far away now?)
Correct! :punch:
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: Attribute: data-embed-popup-caption-template

09 Nov 2021, 06:08

In Files app 0.3.0 [demo] I have included new IPTC fields headline, creator, credit, copyright, city, sub-location and province-state. That is in addition to the existing title, description and keywords of course. There options will display by default in Files app, and can be assigned to display in Embed by using caption-template.
 
traxnamibia
Experienced
Topic Author
Posts: 36
Joined: 17 May 2021, 08:16

Re: Attribute: data-embed-popup-caption-template

10 Nov 2021, 01:05

Many thanks!
I'll check it out as soon as I can.