* Plugin to output Thumbnails from Frame Links

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
ADC65
Superstar
Posts: 457
Joined: 09 Jul 2007 10:27
Family Historian: V7

Plugin to output Thumbnails from Frame Links

Post by ADC65 »

I would like to write a plugin but at the moment what I require is beyond my abilities, so I am asking for some guidance please. Being an ex-coder, I don't have too much of a problem in learning Lua and I have made some progress in it. However, getting at the data I need in FH is another matter.

My aim is to output thumbnail-sized JPEG files from selected media I have in FH. That sounds simple enough I know, but I have fairly stringent parameters, as described below.

1. For each Individual in my file, there will be zero or more media items attached to them.
2. Of those media items, either zero or exactly one will be NOT be flagged with "Exclude from Reports/Exclude from Diagrams".
3. If there is a media item that is not flagged with the Excludes, it will have a frame link to the Individual. Note that the media may have other frame links to other individuals, and those frames may or may not have Exclude flags. I am only interested in the Frame Link for the current Individual.
4. I wish to output the Frame Link (not the whole media item) into a JPEG file, which needs to be named "text-string" concatenated with the INDI number - for example "ADCTREE.I1001.jpeg"
5. The Frame Link image being output needs to be resized to a fixed square, e.g., 100 x 100 pixels.

My guess is I need to run through the INDI records, but I'm then lost in how to decide whether it has the appropriate media.

Any pointers gratefully received.
Adrian
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Plugin to output Thumbnails from Frame Links

Post by tatewise »

Ok, so I guess you know how to set up data item loops.
Have you looked at the How to Write Plugins help page with all the API functions and sample scripts?
Have you looked at the FHUG Knowledge Base Plugins section?
Maybe I assume too much. Do you know how to use the API to access Project data items using data references?

Outer loop is through INDI records.
Inner loop is through OBJE tags that hold the Media tab files.
The Exclude options are held in the _EXCL subtag with values ALL or RPT, etc, but you want there to be no _EXCL tag.
So as soon as you find an INDI.OBJE[n] entry with no _EXCL then that is the Media entry you are looking for.
Otherwise, the OBJE loop will terminate without finding any candidate Media.

The OBJE tag holds a link to the Media record whose FILE tag holds the file path usually relative to the Media folder.

The original OBJE holds its frame in the _AREA subtag with the format _AREA {439,20,608,1222}.
Where the pixel numbers represent {Top,Left,Bottom,Right}.
i.e.
439 is the number of pixels that Top of the frame is down from the top of the image.
608 is the number of pixels that Bottom of the frame is down from the top of the image.
20 is the number of pixels that the Left of the frame is in from the left of the image.
1222 is the number of pixels that the Right of the frame is in from the left of the image.

What I don't understand is how you are going to resize that to a 100 x 100 pixel square.
Are you planning to crop or stretch or what to perform the transformation?

You can get the INDI record id integer using the id = fhGetRecordId(ptr) function.
So the filename text is formed using "ADCTREE.I" .. tostring(id) .. "1001.jpeg".

You will need to use the IM image library module to create the thumbnail.
It can load the original image file, crop, resize & convert the image and finally save the thumbnail.
My Export Gedcom File plugin uses it extensively to export the Media frames.
I can go into details when you have the basic looping and Media selection working.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5464
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Plugin to output Thumbnails from Frame Links

Post by ColeValleyGirl »

Thre are a couple of iterators in the fhUtils library that you might find useful: allitems and records.
User avatar
ADC65
Superstar
Posts: 457
Joined: 09 Jul 2007 10:27
Family Historian: V7

Re: Plugin to output Thumbnails from Frame Links

Post by ADC65 »

Mike, as always you are an absolute treasure. Thank you for your guidance.

I have been ploughing through the help files, etc., that you suggested and I'm making progress. This is probably a case of running before I can walk.

I was getting confused trying to see how to get the Media OBJE via the INDI record, but you have made that a lot clearer, thank you. Also, the _EXCL subtag had eluded me. I can hopefully make a shaky start now.

I am a bit more comfortable with the Media resizing, I had briefly looked at how you do it in your Export plugin as I make use of that to resize Media when I run it. My Frame Links are as square as I can make them by eye, so resizing them to be 100 on the longest side will be fine. I have plans to write a plugin at a later date which will actually change the co-ordinates of the AREA subtag to make it a perfect square (I've done this manually as a test and I'm happy enough with the results).

Thanks again. I will let you know how I get on. Undoubtedly there will be more questions.
Adrian
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
User avatar
ADC65
Superstar
Posts: 457
Joined: 09 Jul 2007 10:27
Family Historian: V7

Re: Plugin to output Thumbnails from Frame Links

Post by ADC65 »

Thanks Helen, I will take a look there.
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Plugin to output Thumbnails from Frame Links

Post by tatewise »

Adrian, here are some tips you might find useful:
  1. How to discover unfamiliar data reference tags.
    Use any of the Dat Reference Assistants that are found with many of the customisation tools but a Query is best.
    In any Query, on its Columns tab, use the Fields pane.
    In the droplist Menu under the box below that pane choose the Show Both in Box option.
    Then for example the Exclude From option reveals its tag is _EXCL.
    (Unfortunately, there are a few 'hidden' tags such as _AREA that can only be discovered by inspecting GEDCOM files.)
    *
    QueryFields.png
    QueryFields.png (34.62 KiB) Viewed 2160 times
    *
  2. How to terminate a Plugin loop prematurely.
    Once you have processed the chosen thumbnail use the break statement to terminate the OBJE tag loop.
    Since OBJE in the Media tab loop in Pref order, you only need to set Exclude From on the lower numbered Pref Media.
    i.e. The lowest Pref Media without an _EXCL tag will create the thumbnail, so later Media can also omit the _EXCL tag.
    *
  3. Methods for identifying Thumbnail Media
    Instead of utilising the _EXCL setting, you could use some other Media field to identify the Thumbnail image.
    You could use the Link Note in the Edit Media Item dialogue and set that to say [[Thumbnail]].
    Then the OBJE loop would look for a _NOTA tag whose value contains [[Thumbnail]].
    The option to Use Link Note as Caption does not need to be ticked, but if it is, the [[ brackets ]] will exclude the text [[Thumbnail]] from the caption in Reports.
    An alternative field is the Source Note with the SOUR2 tag but that is only accessible via the All tab.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ADC65
Superstar
Posts: 457
Joined: 09 Jul 2007 10:27
Family Historian: V7

Re: Plugin to output Thumbnails from Frame Links

Post by ADC65 »

Thank you Mike, all great advice which I will take on board. I had used the field picker as suggested in your point (1) but I got a bit bogged down in recursive data and managed to miss what I was looking for. Your point (3) is very helpful; in my case using the _EXCL subtag works, but your method leaves more flexibility in case I did want to leave more than one media item without _EXCL.

Many thanks
Adrian
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
User avatar
ADC65
Superstar
Posts: 457
Joined: 09 Jul 2007 10:27
Family Historian: V7

Re: Plugin to output Thumbnails from Frame Links

Post by ADC65 »

I don't believe the resultant plug in will be of any use to anyone except myself as it is very specific to my set up. However, if anyone wants to take it and modify it for their use, it should be easy to do, and I can probably help.

As per the first post in this topic, the plugin runs through media items and will produce a 100x100 pixel thumbnail for the first media item it finds for each person that does not have both EXCLUDE tags set.

Edited: Please message the author if you want a copy.
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
Post Reply