diff --git a/components/fpexif/fpeexifdata.pas b/components/fpexif/fpeexifdata.pas index c361c23f7..38379c3e1 100644 --- a/components/fpexif/fpeexifdata.pas +++ b/components/fpexif/fpeexifdata.pas @@ -95,6 +95,8 @@ type AData: TBytes; ACount: Integer; ALkupTbl: String = ''): Integer; function AddOrReplaceTag(ATag: TTag): Integer; + function AddOrReplaceTagByID(ATagID: TTagID): TTag; + function AddOrReplaceTagByName(AFullTagName: String): TTag; function AddTag(ATag: TTag): Integer; function AddTagByID(ATagID: TTagID): TTag; function AddTagByName(AFullTagName: String): TTag; @@ -640,6 +642,28 @@ begin Result := AddTag(ATag); end; +function TExifData.AddOrReplaceTagByID(ATagID: TTagID): TTag; +var + idx: Integer; +begin + idx := IndexOfTagID(ATagID); + if idx = -1 then + Result := AddTagByID(ATagID) + else + Result := FTagList[idx]; +end; + +function TExifData.AddOrReplaceTagByName(AFullTagName: String): TTag; +var + idx: Integer; +begin + idx := IndexOfTagName(AFullTagName); + if idx = -1 then + Result := AddTagByName(AFullTagName) + else + Result := FTagList[idx]; +end; + function TExifData.AddTag(ATag: TTag): Integer; var parentID: TTagID; diff --git a/components/fpexif/readme.txt b/components/fpexif/readme.txt index 24d006c16..e7a9af357 100644 --- a/components/fpexif/readme.txt +++ b/components/fpexif/readme.txt @@ -74,19 +74,19 @@ See also "console_demo". // Read the shutter speed used when taking an image from EXIF data WriteLn( 'ShutterSpeed: ', - imgInfo.ExifData.TagByName['ShutterSpeed'].AsString + imgInfo.ExifData.TagByName['ShutterSpeed'].AsString ); - - // or better (to avoid the exception if this particular tag does not exist): - tag := imgInfo.ExifData.TagByName['ShutterSpeed']; - if tag <> nil then WriteLn('ShutterSpeed: ', tag.AsString); + + // or better (to avoid the exception if this particular tag does not exist): + tag := imgInfo.ExifData.TagByName['ShutterSpeed']; + if tag <> nil then WriteLn('ShutterSpeed: ', tag.AsString); // Add a user comment to the EXIF data imgInfo.ExifData.TagByName['UserComment'].AsString := 'My best photo'; // Save the modified meta data to file imgInfo.SaveToFile('MyImage_edited.jpg'); - // or: imgInfo.Save; // overwrite currently loaded file + // or: imgInfo.Save; // overwrite currently loaded file end; finally diff --git a/components/fpexif/tests/unittest/common/fetexifbe.pas b/components/fpexif/tests/unittest/common/fetexifbe.pas index bb1cbc6dc..e3ff78550 100644 --- a/components/fpexif/tests/unittest/common/fetexifbe.pas +++ b/components/fpexif/tests/unittest/common/fetexifbe.pas @@ -345,6 +345,10 @@ begin CheckTrue(lTag <> nil, 'Tag "ExifImageHeight" not found for writing'); lTag.AsInteger := 267; + lTag := imgInfo.ExifData.AddTagByName('EXIF.Artist'); + Checktrue(lTag <> nil, 'Tag "EXIF.Artist" not found for writing'); + lTag.AsString := 'fpexif-artist'; + // Save to file; // Takes the image data from WorkFile_WithExif, replaces its EXIF with the // current EXIF structure and writes to WorkFile_NoExif. @@ -422,6 +426,10 @@ begin CheckTrue(lTag <> nil, 'Tag "ExifImageHeight" not found'); CheckEquals(267, lTag.AsInteger, 'Value mismatch of tag "ExifImageHeight"'); + lTag := ImgInfo.ExifData.TagByName['EXIF.Artist']; + CheckTrue(lTag <> nil, 'Tag "EXIF.Artist" not found'); + CheckEquals('fpexif-artist', lTag.AsString, 'Value mismatch of tag "EXIF.Artist"'); + // No thumbnail in dest file! finally diff --git a/components/fpexif/tests/unittest/common/fetexifle.pas b/components/fpexif/tests/unittest/common/fetexifle.pas index 226fbdc61..2cf8b98d0 100644 --- a/components/fpexif/tests/unittest/common/fetexifle.pas +++ b/components/fpexif/tests/unittest/common/fetexifle.pas @@ -496,6 +496,10 @@ begin CheckTrue(lTag <> nil, 'Tag "ExifImageHeight" not found for writing'); lTag.AsInteger := 150; + lTag := imgInfo.ExifData.AddTagByName('EXIF.Artist'); + Checktrue(lTag <> nil, 'Tag "EXIF.Artist" not found for writing'); + lTag.AsString := 'fpexif-artist'; + // Save to file; // Takes the image data from WorkFile_WithExif, replaces its EXIF with the // current EXIF structure and writes to WorkFile_NoExif. @@ -558,6 +562,10 @@ begin CheckTrue(lTag <> nil, 'Tag "ExifImageHeight" not found for reading'); CheckEquals('150', lTag.AsString, 'Value mismatch of tag "ExifImageHeight"'); + lTag := ImgInfo.ExifData.TagByName['EXIF.Artist']; + CheckTrue(lTag <> nil, 'Tag "EXIF.Artist" not found'); + CheckEquals('fpexif-artist', lTag.AsString, 'Value mismatch of tag "EXIF.Artist"'); + finally imgInfo.Free; end;