Recent

Author Topic: fpexif - create a tag  (Read 1467 times)

GordonFindlay

  • Guest
fpexif - create a tag
« on: July 22, 2024, 10:29:59 am »
I'm just starting to explore the use of EXIF data, using the fpexif package.

The tutorial in the readme.txt file updates a tag with

Code: Pascal  [Select][+][-]
  1. imgInfo.ExifData.TagByName['UserComment'].AsString := 'My best photo'

and the example console_demo included with the package does similar things.

This fails with an access violation if the tag  UserComment  does not already exist -  tested with

Code: Pascal  [Select][+][-]
  1. imgInfo.ExifData.TagByName['UserComment'] = Nil

Not many images - I'm concerned with .jpg mainly - have no instance (even a null one) of the UserComment tag, but enough do to make me want to add one where necessary.

I've tried various versions of the AddTag procedures without much success. So how can I add the tag to the image prior to setting its value?

TIA
Gordon
[SuSE Linux; Lazarus 3.4; fpc 3.2.2]

wp

  • Hero Member
  • *****
  • Posts: 12367
Re: fpexif - create a tag
« Reply #1 on: July 23, 2024, 12:10:43 am »
When setting values to EXIF tags it is better to use the AddTagByID or AddTagByName functions, they can also be used for replacing existing tags. I know, this is a bit counter-intuitive, but putting this into the TagByID[] and TagByName[] setters would have lead to inconsistencies within the library with other metadata.

Code: Pascal  [Select][+][-]
  1.  // Add (or replace) user comment
  2. tag := ImgInfo.ExifData.AddTagByName('UserComment');
  3. tag.AsString := 'This is my favorite photo.';
  4.  
  5. // or as 1 line:
  6. ImgInfo.ExifData.AddTagByName('UserComment').AsString := 'This is my favorite photo.';

GordonFindlay

  • Guest
Re: fpexif - create a tag
« Reply #2 on: July 23, 2024, 10:03:47 am »
Many thanks for this advice - one more bit of the puzzle is working.

Slainte
Gordon

 

TinyPortal © 2005-2018