Import text from a txt file in a particular metadata tag only

Started by hammad9860, May 25, 2021, 12:22:19 PM

Previous topic - Next topic

hammad9860

So I'm going through a personal project of making images searchable by the text in them (such as screenshots). I run an OCR script that uploads photo to Google Drive and it returns a multi-line .txt file with all of the text that was in the photo. Now I want to put that .txt file's text into the Comment tag of the .jpg photo (because Comment tag supports multi-line input). In such way, the Windows would be able to search the photo with the text.

I thought it would be a simple task for exiftool to import text from a text file but I couldn't find any solution to this. I have a bunch of screenshots and want to make this process automatic with a batch file. So is there anyway to do this or some other approach for this.

And thanks for this amazing program! It's really helpful.

StarGeek

As long as the text files are separate for each OCR, you would use the -TAG<=DATFILE option.
exiftool "-XPComment<=temp.txt" file.jpg

Here I used the XPComment tag as that is what Windows will read under the "Comments" property.  This is different from the Comment tag, which is the jpeg specific comment, not read by Windows, and extremely fragile and prone to being overwritten.

Also, exiftool can write multiple lines to nearly any string based tag, including things like Keywords (which was a real headache for me to fix long time ago).  See FAQ #21, which includes the above mentioned option.

Myself, I tend to use the -E (-escapeHTML) option and have an Autoit script that applies the conversion to the contents of my clipboard.  It uses the HtmlEntities function.  I then just add the -E option and paste.
#include <EncodeHtmlEntities.au3>
$sub = clipget()
_HtmlEntities_Encode($sub)
$sub = StringRegExpReplace($sub,"(\x0d\x0a|\x0d|\x0a)",'&#x0a;')
ClipPut($sub)

So this:
Line 1
Line 2
Line 3

would end up with a command like this
exiftool -Description="Line 1&#x0a;Line 2&#x0a;Line 3" -E file.jpg
and be embedded with the line feeds.

You could probably add such functionality with whatever procedure you're using to upload the imageand retrieve the text and skip the temp file altogether.
"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

hammad9860

Thanks a bunch! That first simple line of code did it. You really made my day.