Extracting part of a Windows JPG filename and copying into an Exif tag

Started by mpegleg, June 14, 2019, 01:48:36 AM

Previous topic - Next topic

Hayo Baan

Right, so it looks like you found images that cause exiftool to trigger a syntax error in the code! Can you share such an image?

Also, there was indeed an error in my regexp that would not leave the text blank in the two last examples. You should be using s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/ as the regular expression (negative look-ahead assertion in front of the . instead of after it, this allows for an empty text part for what you want to keep).
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Yes. But the picture is REALLY CR*P, so don't laugh. It's one my Uncle took (true. Not me!) while in Germany, and has been heavily manipulated. Could be interesting for a debug exercise for you all, so once I check that's there's nothing too personal in the Exif tags, I won't modify it, and I'll upload it.
OS: Windows 11 Pro

mpegleg

OK. So here is the culprit!... and I notice this is the resized down/modified version that I normally show on the TV. I'll check the original in a minute once I find it. I can't use the PIX ids to search because I made these test ones up. lol. I'm sure it will cause the same errors. Interesting. I'll upload that too when I find it...
OS: Windows 11 Pro

mpegleg

Aha. Looking at the original filename... this probably explains a lot!

2010-08-12 08-48-11 IMG_5588 [PIX579159] (original full-res photo was damaged) modx1

It's now coming back to me. I now remember it wouldn't load into Photoshop, or any other image editor and I ended up using some way of trying to fix it. Obviously I only half completed that job!
OS: Windows 11 Pro

mpegleg

Here's the "not really an original at all" original. It's actually a very heavily downsized wreck of a photo. lol

EDIT: I just tried to download it and I got this: our attachment has failed security checks and cannot be uploaded. Please consult the forum administrator

So it obviously has a LOT of issues with it. It's also only 181 kB ! whereas all the other full-size original images in the same folder average about 4 to 5 MB. I do remember when I first saw it, and saw the very small size... l was left thinking "Where'd this oddball image come from?", but it is in sequence with the other images.
OS: Windows 11 Pro

Hayo Baan

Quote from: mpegleg on June 17, 2019, 06:25:46 AM
OK. So here is the culprit!... and I notice this is the resized down/modified version that I normally show on the TV. I'll check the original in a minute once I find it. I can't use the PIX ids to search because I made these test ones up. lol. I'm sure it will cause the same errors. Interesting. I'll upload that too when I find it...

Nope, I don't get the perl errors you get; the file is updated just fine. Note though that it indeed has quite some (very minor) issues:
$ exiftool -validate -warning -a -G0:1 "I don't want this text but [PIX172643] I do want this text modx but I don't want this.jpg"
[ExifTool]      Validate                        : 8 Warnings (all minor)
[ExifTool]      Warning                         : [minor] Non-standard ExifIFD tag 0xea1c Padding
[ExifTool]      Warning                         : [minor] Non-standard IFD0 tag 0xea1c Padding
[ExifTool]      Warning                         : [minor] Fixed incorrect URI for xmlns:MicrosoftPhoto
[ExifTool]      Warning                         : [minor] IFD0 tag 0x0100 ImageWidth is not allowed in JPEG
[ExifTool]      Warning                         : [minor] IFD0 tag 0x0101 ImageHeight is not allowed in JPEG
[ExifTool]      Warning                         : [minor] IFD0 tag 0x0102 BitsPerSample is not allowed in JPEG
[ExifTool]      Warning                         : [minor] IFD0 tag 0x0106 PhotometricInterpretation is not allowed in JPEG
[ExifTool]      Warning                         : [minor] IFD0 tag 0x0115 SamplesPerPixel is not allowed in JPEG


It updated fine though:
$ exiftool -m -overwrite_original '-XPcomment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;}' "I don't want this text but [PIX172643] I do want this text modx but I don't want this.jpg"
    1 image files updated
$ exiftool -G0:1 -a -XPcomment "I don't want this text but [PIX172643] I do want this text modx but I don't want this.jpg"
[EXIF:IFD0]     XP Comment                      : I do want this text

(had to switch the double quote to single on my Mac)
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Yes, so I wouldn't recommend wasting too much more time on this image. It was corrupted to start with. Why out of my 40000+ images did I have to choose that particular one to test with!  ::) *slap!*
OS: Windows 11 Pro

Hayo Baan

Yes, but it would still be nice to have the file since it triggers an error in the exiftool code. If you can't post it here (perhaps zipping it works), you can also send it to me info@hayobaan.nl.
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Your wish is my command...

Don't know why I didn't think of zipping it. I hope a RAR is ok?
OS: Windows 11 Pro

mpegleg

Also I just searched through my Archive backups. This one has been untouched since it was last messed around with in 2010...

It's obviously still not the Absolute "fresh from the camera memory card" corrupted original, but it's the oldest one I could find.
OS: Windows 11 Pro

Phil Harvey

To get all of those Perl errors in Photoshop.pm, your installation must be corrupted somehow.  Delete the temporary files (C:\Users\USER\AppData\Local\Temp\par-xxx) and try again.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mpegleg

I'll do that Phil, just to be sure, but I doubt anything is corrupted with ExifTool apart from that %$#!#$ photo. I'm not getting any errors on any other images. Like I was saying to Hayo Baan, it was just a very poor random choice of an image to use for testing with. Pure chance. Perhaps I should have deleted it.

It was a photo that had been marked for deletion because I couldn't originally load it into any photo editor, and I managed to get it to a state where I could view it, but I knew it was still corrupted. Anyway... I'm off to delete the temps....
OS: Windows 11 Pro

Hayo Baan

Indeed, looks like a corrupted install at your end; that file gives me no issues at all, even validation only gives a very minor warning: [minor] Odd offset for IFD0 tag 0x0132 ModifyDate
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

If you aren't getting errors with other images it is because they don't contain Photoshop information.  It is the Photoshop module that is corrupted.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mpegleg

Yes. Of course you guys were right! I just deleted the Temp files, and restarted.

You may have read one of my posts a while back in this thread where I was talking about having multiple BSODs "Blue screens of Death". Well. I guess things really did get pretty screwy. I also did a successful recover from a Acronis True Image restore, which is why I didn't think anything could be too screwed up.

Anyway, I just tried that same file again.. and guess what. No Errors!  :-[

Thanks again, and sorry for all the drama. I'll slink off somewhere and hide now  :)

Thanks Phil,

...and Hayo... thanks for the help. I haven't had time to fully work other tests on your code yet, but I will.

Cheers,
-Paul

ps. I think I'll reload another earlier True Image restore going back about a week or so, just to be on the safe side. I don't really don't feel that my system is stable.
OS: Windows 11 Pro