Recent

Author Topic: FPExif generates exception when saving updated DateTimeOriginal  (Read 3193 times)

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Hi wp,

I'm using the latest fpExif snapshot und when I try to save a modified DateTameoriginal datetime back to the JPEG file, the library generates an exception

Code: Pascal  [Select][+][-]
  1.  
  2.    ...
  3.    
  4.    L_TagDTOriginal := L_ImageInfo.ExifData.TagByName['DateTimeOriginal'];
  5.    if (L_TagDTOriginal <> nil) then
  6.        TDateTimeTag(L_TagDTOriginal).AsDateTime := _IM_PhotoDT;
  7.  
  8.    L_ImageInfo.WriteJFIFandEXIF := true;
  9.    L_ImageInfo.SaveToFile(_IM_FullName);    <---- triggers an exception
  10.  
  11.      
  12.  

I send you a PM with the URL to download the photo.

Many thanks for your help
« Last Edit: March 24, 2021, 11:53:10 am by rpetges »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #1 on: March 24, 2021, 05:57:22 pm »
Please check the new version. There was a bug in the size calculation of the EXIF segment which became apparent only because you wanted to save a JFIF segment along with the EXIF segment.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #2 on: March 24, 2021, 08:03:24 pm »
Tried snapshot r7981 and I still get the code exception.

To be sure, I deleted all generated binaries but still get an exception.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #3 on: March 24, 2021, 10:26:37 pm »
This is the code that I used for testing:

Code: Pascal  [Select][+][-]
  1. program change_date_demo;
  2.  
  3. uses
  4.   SysUtils,
  5.   fpeMetaData, fpeTags, fpeExifData;
  6.  
  7. var
  8.   imgInfo: TImgInfo;
  9.   tag: TTag;
  10.  
  11. begin
  12.   imgInfo := TImgInfo.Create;
  13.   try
  14.     // Read file
  15.     imgInfo.LoadFromFile('MyPhoto.jpg');
  16.  
  17.     // Check for EXIF meta data
  18.     if imgInfo.HasEXIF then begin
  19.       tag := imgInfo.ExifData.TagByName['DateTimeOriginal'];
  20.       if tag <> nil then
  21.           TDateTimeTag(tag).AsDateTime := Now;
  22.  
  23.       // Save the modified meta data to file
  24.       imgInfo.WriteJFIFandEXIF := true;
  25.       imgInfo.SaveToFile('MyPhoto_edited.jpg');
  26.     end;
  27.   finally
  28.     imgInfo.Free;
  29.   end;
  30. end.  

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #4 on: March 24, 2021, 11:09:32 pm »
Ah ok, I use the same filename for opening and saving.

I now just tried to replace imgInfo.SaveToFile('MyPhoto.jpg') by imgInfo.Save and get the exception. Does this work for you ?
 

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #5 on: March 25, 2021, 12:03:55 am »
I see - the previous commit was wrong... Need to investigate further.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #6 on: March 25, 2021, 02:17:47 pm »
Please test the new revision.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #7 on: March 25, 2021, 05:22:16 pm »
Nope, does not work. Still get an exception.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #8 on: March 25, 2021, 05:43:41 pm »
Did you replace the overwritten file by a "fresh" copy? This is important because the file got damaged by the previous versions.

For completeness, this is the code which worked for me:
Code: Pascal  [Select][+][-]
  1. program change_date_demo;
  2.  
  3. uses
  4.   SysUtils, FileUtil,
  5.   fpeMetaData, fpeTags, fpeExifData;
  6.  
  7. const
  8.   //fn = 'BlueSquare.jpg';
  9.   fn = 'MyPhoto.jpg';
  10.   fn_work = 'test.jpg';
  11.   fn_out = 'output.jpg';
  12. var
  13.   imgInfo: TImgInfo;
  14.   tag: TTag;
  15.  
  16. begin
  17.   CopyFile(fn, fn_work);
  18.  
  19.   imgInfo := TImgInfo.Create;
  20.   try
  21.     // Read file
  22.     imgInfo.LoadFromFile(fn_work);
  23.  
  24.     // Check for EXIF meta data
  25.     if imgInfo.HasEXIF then begin
  26.  
  27.       // Change date
  28.       tag := imgInfo.ExifData.TagByName['DateTimeOriginal'];
  29.       if tag <> nil then
  30.         TDateTimeTag(tag).AsDateTime := Now;
  31.  
  32.       // Save the modified meta data to file
  33.       imgInfo.WriteJFIFandEXIF := true;
  34. //      imgInfo.SaveToFile(fn_out);
  35.       imgInfo.Save;
  36.     end;
  37.   finally
  38.     imgInfo.Free;
  39.   end;
  40. end.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #9 on: March 25, 2021, 06:18:33 pm »
I took your code and created a whole new simple project and then it works.

However the same code fails in my application.

Could it be related to compiler settings ? I'm using Lazarus 2.0.12 and FPC 3.2.0


wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #10 on: March 25, 2021, 06:34:42 pm »
Can you remove unnecessary parts from your application and post it (or if you cannot make it public store it in some cloud and send me the link via PM)? Is it still about the same picture? The JPEG standards are not always obeyed by all images.

Could it be related to compiler settings ? I'm using Lazarus 2.0.12 and FPC 3.2.0
I don't think so. And I did check Laz 2.0.12/FPC 3.2.0.
« Last Edit: March 25, 2021, 07:58:48 pm by wp »

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #11 on: March 25, 2021, 07:51:48 pm »
Yes, it is still the same picture.

I will further investigate on my side and keep you informed.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #12 on: March 25, 2021, 09:00:24 pm »
Solved.

It was related to Compiler/Code Generation setting problems. I removed the <Linking> and <CodeGeneration> section from the project file (*.lpi). After reconfiguring some of the options in the Lazarus IDE, I can now successfully compile the application and changing the image works fine as well with the new fpExif snapshot. :)

Thank you for your support.



wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #13 on: March 25, 2021, 09:50:16 pm »
What were your settings? I would like to reproduce your issue, maybe there's still a bug in fpexif related to this.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: FPExif generates exception when saving updated DateTimeOriginal
« Reply #14 on: March 25, 2021, 10:39:55 pm »
Sent you a PM with the link to the project file.

However, I restored the complete project that failed before, but now it works even with the old configuration. Don't know if other files outside the project folder were modified as well when I changed the LPI file and recompiled the application.

Really strange, but I don't think there is an issue with your latest snapshot. I'm quite sure there was something wrong on my side as well.

In the old LPI file, I needed to uncheck the I/O (-Ci) and Verify method calls (-CR) options to get the application work correctly. Enabling both options generated the exception.
« Last Edit: March 25, 2021, 10:43:29 pm by rpetges »

 

TinyPortal © 2005-2018