How can I see trailing spaces in tag vaules?

Started by busywait, August 19, 2017, 07:54:10 AM

Previous topic - Next topic

busywait

I've got a Olympus E-PL7 camera, and in the EXIF data for every image that I take the Image Description tag value is

OLYMPUS DIGITAL CAMERA         

(There are 9 trailing spaces at the end of that string.)

It's hard to see spaces on the Windows console, but I can output all tag values to a file if I run exiftool with this arg file

-w
%f-%e-exif.txt

(My text editor will let me show space characters in a file when I want to see them.)

Then I see this in the output file:

ExifTool Version Number         : 10.60
File Name                       : P7310173.ORF
...
Image Description               : OLYMPUS DIGITAL CAMERA
Make                            : OLYMPUS IMAGING CORP.
Camera Model Name               : E-PL7
...


There are no trailing spaces at the end of the Image Description value. That made it hard for me to find the correct string to use in the arg file that I was debugging:

#-v2
# There are 9 spaces at the end of this value:
-ImageDescription-=OLYMPUS DIGITAL CAMERA         
# This value will only be written if -= option above found a match
#-ImageDescription=Picture from Emma's digital camera


Is there a quick way to reveal spaces or other tricky characters if I need to do this again?

busywait

Or even better for me, is there an option to ignore leading/trailing space when doing value comparisons?

herb

Hello Phil, hello busywait,

I also had discussed the topic of trailing spaces with Phil in September 2010.
See https://exiftool.org/forum/index.php/topic,2815.msg12694.html#msg12694

Responsible for this is the line $val =~ s/\s+$//; which removes all trailing spaces . It is in file "exiftool" of perl distribution; resp in file "17aa1085.pl" (on my Win7 system).

Phil, what do you think about a new feature - trailing spaces - based on userParams:
if ( NOT $et->Options(UserParam => 'trailingSpace' )   $val =~ s/\s+$//;

I hope the syntax of the above line is ok.
Best regards
Herb

busywait

Thanks Herb,

I see how that new option would help me see the exact value for Image Description.

Why just trailing white space, and not leading as well as trailing space?

Thinking about my usage of the tool here, I suppose I only noticed this problem because exiftool was not consistent in handling the trailing space. If it had been consistent in always chopping the trailing space (when displaying values *and* when comparing values, and when assigning values) then I would not have noticed the issue.

Regardless of any new option to preserve white space I think it would be best if exiftool used the same behavior in the -=, += and if logic as it does to display values.

busywait

And finally on the subject of trailing space, I've lost a little time over the last day because I accidentally had trailing space in my exiftool arg file.

If I accidentally put a space after this -if

-if
$ImageDescription-=


Then I get this error:

Invalid TAG name: if
Ignored superfluous tag name or invalid option: -if
======== $ImageDescription eq 'OLYMPUS DIGITAL CAMERA         ' [1/2]
Error: File not found - $ImageDescription eq 'OLYMPUS DIGITAL CAMERA         '


Is it valid to have a tag name or option name that ends with a space? Could lines that start with - safely have trailing space chomped :)

Phil Harvey

I would recommend the JSON option for output if you want to see all the spaces.

I can't simply chomp spaces at the end of argfile lines because you may want to do something like this:

"-ImageDescription=OLYMPUS DIGITAL CAMERA         "

But true, there are many cases where I could implement better validation and warning messages for suspicious looking arguments.  However it is easy to run into trouble doing this and disabling a perfectly valid functionality because I forgot about a special case or unanticipated usage.

- 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 ($).

busywait

Thank you for your time. Your -json output format suggestion is perfect to show clearly the hidden space at the end of my tag value. Hopefully that will save me a little time in the future.

While I was reviewing output formats, I saw -argFormat, and and noticed that the exported data in that format was stripped of trailing space - is that intentional?

json export shows trailing space:

  "EXIF:ImageDescription": "OLYMPUS DIGITAL CAMERA         ",


exiftool args format export has stripped trailing space:

-EXIF:ImageDescription=OLYMPUS DIGITAL CAMERA


A little bit more complication to this small task: Adobe Elements editor strips the trailing space when saving edited images, so I have to check for both variations if I want to strip Image Descriptions with this default value. But my image slide show will be better for it, because it won't have irrelevant captions overlaid :)

StarGeek

Quote from: busywait on August 19, 2017, 08:50:45 AM
Or even better for me, is there an option to ignore leading/trailing space when doing value comparisons?

For this, you could add -api "Filter=s/^\s+|\s+($)//g" when you want to do a comparison.

exiftool -if "$ImageDescription eq 'OLYMPUS DIGITAL CAMERA'" -api "Filter=s/^\s+|\s+($)//g"

If you wanted to bulk remove leading/trailing spaces
exiftool -if "$ImageDescription ne $ImageDescription#" -api "Filter=s/^\s+|\s+($)//g" -tagsfromfile @ -ImageDescription
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

busywait

Thanks StarGeek

That would simplify my arg file. I tried that in the example file below (and also putting the -api directly in to the command line), and it did not match in cases where there was trailing space. I also tried simplifying the regex to ignore any space, s/\s+//g.

I wasn't using -if like you suggested, I was using the -= operator... I guess that's my problem?


# Uncomment this line to show helpful information when this command is run
-v2

#Ignore leading and trailing whitespace during comparisons
-api
Filter=s/^\s+|\s+($)//g

-ImageDescription-=OLYMPUS DIGITAL CAMERA
# If an image has been edited then the Description will likely have been
# copied to the XMP dc:Description element, so check that too.
-Description-=OLYMPUS DIGITAL CAMERA
# Adobe software also copies Image Description to the IPTC Caption Abstract
-Caption-Abstract-=OLYMPUS DIGITAL CAMERA


Because I'm testing and setting/clearing three different tags I don't see how I can use -if in this args file, but I'll take another look tomorrow evening. For now, my problem is solved by doubling up the three checks:


# There are 9 spaces at the end of this value that my camera writes:
-ImageDescription-=OLYMPUS DIGITAL CAMERA         
# Some software might have stripped the trailing spaces, so also look for a fixed
# version with no trailing spaces:
-ImageDescription-=OLYMPUS DIGITAL CAMERA

# If an image has been edited then the Description will likely have been 
# copied to the XMP dc:Description element, so check that too.
# ACDSee software will copy the trailing spaces to Description
-Description-=OLYMPUS DIGITAL CAMERA         
# Adobe software strips the trailing space
-Description-=OLYMPUS DIGITAL CAMERA

# Adobe software also copies Image Description to the IPTC Caption Abstract
-Caption-Abstract-=OLYMPUS DIGITAL CAMERA


StarGeek

Quote from: busywait on August 20, 2017, 06:42:37 PMI also tried simplifying the regex to ignore any space, s/\s+//g.
Remember, that will remove all spaces, so you would have to compare against OLYMPUSDIGITALCAMERA.

QuoteI wasn't using -if like you suggested, I was using the -= operator... I guess that's my problem?

Yes, sorry.  The api filter option won't work with -=.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype