Main Menu

Batch Embed Thumbnails

Started by Chris C., May 08, 2021, 09:30:54 AM

Previous topic - Next topic

Chris C.

Hello again,

So I searched about changing Thumbnail images of files to reflect the new file's content and found that the command

exiftool "-thumbnailimage<=thumb.jpg" image.jpg file.jpg

embeds or updates the thumbnail in file.jpg with the picture in image.jpg.

So I set up a batch operation to reduce all the pictures in a folder to 240x240 image sizes with the suffix _thumb and would like to batch insert these thumbnail size images into my processed files, for better quality viewing than what Photoshop creates during saving the file

I've tried the command

exiftool "-thumbnailimage<=*_thumb.jpg" *.jpg

using the * as a wildcard but it doesn't work at all (to be honest I did expect recursion issues since the thumbnails images were in the same folder, but that was my first attempt and I was going to put the thumbnails in a \_thumb subfolder)

The error messge is

error opening file *_thumb.jpg
Nothing to do

So I'm guessing my syntax is wrong... Could a gentle soul help me out? Like I said previously I'm batch reducing my pictures so that they are created in a subfoldfer with a subfolder suffix something like this (but for all files in the folder):

exiftool "-thumbnailimage<=_THUMBSUBFOLDER\FILENAME_THUMB.JPG" FILENAME.jpg

I have thousands of files to update so you can see how useful it would be if I could find a way to automate the process!

Thanks in advance!!!

StarGeek

From the docs on the -TAG<=DATFILE option (emphasis mine)
     The file name may also be given by a FMT string where %d, %f and %e represent the directory, file name and extension of the original FILE (see the -w option for more details).

Also see the example just below the one you listed.

Try
%d%f_thumb.%e
instead of
*_thumb.jpg
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Chris C.

Quote from: StarGeek on May 08, 2021, 11:14:50 AM
From the docs on the -TAG<=DATFILE option (emphasis mine)
     The file name may also be given by a FMT string where %d, %f and %e represent the directory, file name and extension of the original FILE (see the -w option for more details).

I understand, but like you say, the %f parameter represents the actual name of the original file so can't be used as a placeholder for all the files in a directory...

using the command

exiftool "-thumbnailimage<=%f_thumb.%e"  %f.%e

I would expect the command to replace %f with the actual file it's processing and insert the thumbnail from the image with the same fine name ending in suffix _thumb, but instead I get the error

Error opening file %f_thumb.%e
Error: file not found %f.%e


I've tried all sorts of combinations in the filename, with and without spaces, naming the exact path, using subdirectories for the thumbnails or not, and get the exact same error message. It seems the command doesn't recognize the %f parameter as a placeholder!

To be clearer, I would expect exiftool to process, for example, 

exiftool "-thumbnailimage<=first_file_thumb.jpg" first_file.jpg
then
exiftool "-thumbnailimage<=second_file_thumb.jpg" second_file.jpg
and so on, until all files in the directory have been processed.

I hope I'm not coming on as patronizing - It's just that at this point I'm not sure I was able to make myself clear and can't seem to figure out what I could have done wrong.

StarGeek

Quote from: Chris C. on May 08, 2021, 12:26:40 PM
I understand, but like you say, the %f parameter represents the actual name of the original file so can't be used as a placeholder for all the files in a directory...

Yes, the %f is the filename, which is what you want.  So with %d%f_thumb.%e, given a path of ./IMG_0074.Jpg, the result would be ./IMG_0074_thumb.Jpg.  The %d would be the directory ./, %f would be the filename IMG_0074, and %e would be the extension Jpg.   %d includes the trailing slash and %e does not include the dot.

Quote from: Chris C. on May 08, 2021, 12:26:40 PM
using the command
exiftool "-thumbnailimage<=%f_thumb.%e"  %f.%e

I would expect the command to replace %f with the actual file it's processing and insert the thumbnail from the image with the same fine name ending in suffix _thumb, but instead I get the error

You can't use the % tokens for the files to be processed.  That must be a filename or path.  I suggested replacing only one part of your original command, substituting %d%f_thumb.%e  for *_thumb.jpg, which would result in
exiftool "-thumbnailimage<=%d%f_thumb.%e" *.jpg

QuoteTo be clearer, I would expect exiftool to process, for example, 
exiftool "-thumbnailimage<=first_file_thumb.jpg" first_file.jpg
then
exiftool "-thumbnailimage<=second_file_thumb.jpg" second_file.jpg
and so on, until all files in the directory have been processed.

That is exactly what would happen with my suggested change.  Make sure you read the links I gave.  The example link does exactly what you wanted, except it was embedding a jpeg into the JpgFromRaw tag in a NEF file instead of into the ThumbnailImage.

There is one problem that I just realized, though.  The command will try to embed the thumbs back into themselves.  So there would be a need to exclude those.  That could be done by adding -if "$filename!~/_thumb/"

To put it all together
exiftool -if "$filename!~/_thumb/" "-thumbnailimage<=%d%f_thumb.%e" *.jpg

Or if you went with your idea of a _thumb subfolder, you could skip the -if option with
exiftool "-thumbnailimage<=%d_thumb/%f_thumb.%e" *.jpg
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Chris C.

Quote from: StarGeek on May 08, 2021, 01:06:45 PM
Quote from: Chris C. on May 08, 2021, 12:26:40 PM
using the command
exiftool "-thumbnailimage<=%f_thumb.%e"  %f.%e

I would expect the command to replace %f with the actual file it's processing and insert the thumbnail from the image with the same fine name ending in suffix _thumb, but instead I get the error

You can't use the % tokens for the files to be processed.  That must be a filename or path.  I suggested replacing only one part of your original command, substituting %d%f_thumb.%e  for *_thumb.jpg, which would result in
exiftool "-thumbnailimage<=%d%f_thumb.%e" *.jpg

↑THAT was exactly the problem - I wasn't aware that I shouldn't be using "%" for the files to be processed and that I should use "*" for that instead... Thanks a million, I was getting lost in the documentation trying to figuring it out!

But you've got to admit it wasn't obvious! The difference between tokens and wildcards, forward slash and backslash is enough to drive anyone insane, like what the term 'liberal' means to an American (socialist) versus what it means to a European (capitalist)!

StarGeek

Quote from: Chris C. on May 08, 2021, 01:37:19 PM
But you've got to admit it wasn't obvious!

The % tokens only appear in specific options in the docs.  Those are the only places they can be used.  For example, they cannot be used to copy a filename into a tag, i.e. "-Description<%f.%e" will not work.  It would require "-Description<Filename".

Quoteforward slash and backslash

Since exiftool is a perl program (even the Windows executable is Perl with a minimal perl binary), all backslashes are converted to slashes internally.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Chris C.

I just  wanted to update you all at least those interested in embedding better thumbnail images into pictures and the hurdles I went through and was able to resolve:


Some pictures can't be updated because of 'suspicious' issues with the original EXIF:

1) Use the -m switch, it allows exiftool to work on the files it doesn't like and update them.

2) If that's not enough, have Exiftool rebuild the EXIF, with the caveat that some information be lost and could even make some files unreadable (especially RAW apparently).

In particular, I have many Olympus C8080 files with "Suspicious ExifIFD offset for PrintIM" error and an Internet search turned up ONE result... Of a post I made on these forums 8 years ago!!! As this "PrintIM" is not writable, I managed to bypass the problem of not being able to update the EXIF Thumbnails by having Exiftool rewrite the faulty EXIF data using this  command, based one I found in one of the Exiftool forums (do note my syntax is based on my using exiftool directly from the folder I want to process the pictures from):
exiftool -all= -tagsfromfile @ -all:all -unsafe -icc_profile -m *.jpg
After that, I was able to update the thumbnails for those files without issue!


EXIFs get lost after updating thumbnails:

A nagging problem I kept having without understanding, as there were no error messages from Exiftool, was that some files would simply loose their EXIFs altogether after updating thumbnails. It turns out that thumbnails can't be larger than 64kb in size! I found that out on another forum that pointed to this being a limitation of the EXIF format - my solution was to simply reduce the quality of the JPG Thumbnail image and afterwards the process worked flawlessly.


So I'd like to send a big Thank You to everyone who have helped in this regard. I can now see my pictures in an EXIF Thumbnail enabled Files Manager (Total Commander has that ability since v. 10) in good quality very fast, without the need to render a thumbnail sized preview from the picture file and without needing to build a separate thumbnail database!

And moderators... Please feel free to point out and correct anything I may have gotten wrong!