-1

I like to cut my images' IPTC core Title, Description, Headline characters at to a certain number.

So for example if an image has 300 characters, I would like to cut it at 195 characters to be 195 character long.

It would be great if it would cut it at the nearest word, resulting a title below 195 character

SupWP
  • 17
  • 6

1 Answers1

0

To cut to a specific length, you could use this command:
exiftool -if "length($Title)>195" "-Title<${Title;s/^(.{1,195}).*/$1/s}" /path/to/files/

Cutting on a word, based upon this StackOverflow answer, would be:
exiftool -if "length($Title)>195" "-Title<${Title;s/^(.{1,195}(?!\w)).*/$1/s}" /path/to/files/

This command creates backup files. Add -overwrite_original to suppress the creation of backup files. Add -r to recurse into subdirectories. If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation.

StarGeek
  • 4,948
  • 2
  • 19
  • 30
  • Thank you! However it leaves documents with 197-199 characters. "It would be great if it would cut it at the nearest word, resulting a title below 195 character" – SupWP Aug 03 '20 at 10:15
  • Can you list what a few words on both sides of where the cut is? It should cut to a max of 195 no matter what. Also, are there any characters used that might only be expressed in Unicode? Those would require more than 1 byte per character, but still only be counted as 1 character. – StarGeek Aug 03 '20 at 15:58
  • I just realized the command left the titles they were. I didn't shortened them – SupWP Aug 04 '20 at 18:59
  • Aha. The problem is I need to cut IPTC core Title, Headline and description too – SupWP Aug 04 '20 at 19:04
  • The problem is solved, because my software only takes the Title in account. – SupWP Aug 11 '20 at 07:04
  • Hello! Somehow I would need to cut IPTC core Title, Description and Headline fields. The program I used has changed the way it works. ... I must cut all 3 to maximum 195 character long with cut at a word end – SupWP Dec 01 '20 at 03:26