Thumbnails in EXIF data?

Started by Athelstan, November 15, 2023, 04:43:58 PM

Previous topic - Next topic

Athelstan

I have a couple of questions about removing and inserting thumbnails into the EXIF metadata.

Firstly some information on what I'm trying to do on my Win11 computer.

I have a very large collection of images, some of which have thumbnails embedded and some don't, with the thumbnails residing in several different tags. For all of my images, I intend to delete the existing thumbnails and generate new ones in the -ThumbnailImage tag.

Checking a selection of images I found thumbnails in several tags and suspect there may be others.

-ThumbnailImage
-PhotoshopThumbnail
-PreviewImage


First question. Are there any other tags that contain thumbnail images that may be hiding in the metadata?


I intend to use ImageMagick to create new thumbnail images and use Exiftool to add them to the -ThumbnailImage tag whilst deleting all other thumbnails in the metadata.

To do this I will use a Command Prompt window, navigated to the folder where the images are located. In this window I will run the following command.

for /r %a in (*.jpg) do (Magick convert "%a" -resize 256x256 thumb.jpg &  exiftool -overwrite_original -photoshopthumbnail= -previewimage= "-ThumbnailImage<=thumb.jpg" "%a" &  del thumb.jpg)

I will add other thumbnail tags that need to be removed to it before running it.


Second question. The above command only runs in the basic "Command Prompt" window, not in "Windows Powershell".

How should it be re-written for it to work in Powershell?




StarGeek

Quote from: Athelstan on November 15, 2023, 04:43:58 PMFirst question. Are there any other tags that contain thumbnail images that may be hiding in the metadata?

Use the -list* option to see all tags within a group.  Not all of them will apply to images, though.
exiftool -list -Preview:all

QuoteTo do this I will use a Command Prompt window, navigated to the folder where the images are located. In this window I will run the following command.

for /r %a in (*.jpg) do (Magick convert "%a" -resize 256x256 thumb.jpg &  exiftool -overwrite_original -photoshopthumbnail= -previewimage= "-ThumbnailImage<=thumb.jpg" "%a" &  del thumb.jpg)

Running exiftool in a loop will slow down the process, as the start up time is exiftool's biggest performance hit (see Common Mistake #3) though ImageMagick will probably have more impact on the processing time.  But you might consider running ImageMagick first on all the files, creating the thumbs in a subfolder.  You could then run exiftool to embed all the thumbs with a single command and delete the thumbs subdirectory after.

QuoteSecond question. The above command only runs in the basic "Command Prompt" window, not in "Windows Powershell".

How should it be re-written for it to work in Powershell?

No idea.  I long since gave up on figuring out PS's idiosyncrasies that break commands that work on every other command line.

One thing about PS that you need to be aware of is that it will corrupt binary data that is piped or redirected into a file, such as you might do when extracting thumbnails images.  See this post.
"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

Athelstan

Thanks for the help.

I can easily create thumbnail images of all my files named after their mother files with a "_thumb" suffix. I can save either alongside their mother files or in a centralised folder.

I can process one image at a time

exiftool -ThumbnailImage="C:\Photos\apple_thumb.jpg" "C:\Photos\apple.jpg"
exiftool -ThumbnailImage="C:\Photos\baker_thumb.jpg" "C:\Photos\baker.jpg"
exiftool -ThumbnailImage="C:\Photos\subfolder\charlie_thumb.jpg" "C:\Photos\subfolder\charlie.jpg"

However, I don't know how to make Exiftool automatically pair the thumbnail image with its correct mother image.

Can you suggest an appropriate command please?

StarGeek

Assuming that the thumb for "C:\Photos\apple.jpg" would be "C:\Photos\apple_thumb.jpg", your command would look like

exiftool -if "$Filename!~/_thumb/i" "-ThumbnailImage<=%d%f_thumb.%e" /path/to/files/

Because the thumbs are in the same directory, the -if option needs to be used to avoid trying to embed a thumbnail into the thumbnail.

It would simplify the command if the thumbs were put in a subdirectory.  For example, if the thumbnail was "C:\Photos\thumbs\apple_thumb.jpg" then the command would be

exiftool "-ThumbnailImage<=%dthumbs\%f_thumb.%e" /path/to/files/

%d is the directory of the image currently being processed, with a trailing slash, "C:\Photos\"
%f is the base filename, "apple"
%e is the extension (no leading dot) "jpg"

See the -w (-TextOut) option for more details on the % variables.
"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

Athelstan

Your suggested command set me on the right path.

exiftool "-ThumbnailImage<=%dthumbs\%f_thumb.%e" /path/to/files/

The following is what I did to get it to do what I wanted it to do. I'm spelling it out so that anyone who comes across this thread in the future, and has a similar need to mine, will know what to do without the need to ask.

  • I replaced the %d with the actual path of the thumbnails location.
  • Switched slashes to backslashes for use on Windows11.
  • Added -PhotoshopThumbnail= -PreviewImage= -ThumbnailTIFF= to remove the pre-existing thumbnails lurking in my image files.
  • Added -r to process the subfolders
  • Added -overwrite_original to prevent Exiftool from saving copies of the original files (which would have used several TB of HDD space.
  • Added -P to preserve original date information.
  • Added -progress to enable me to monitor progression of the process

My final command was

exiftool -r -overwrite_original -P -progress -PhotoshopThumbnail= PreviewImage= -ThumbnailTIFF= "-ThumbnailImage<=PATH\TO\THUMBNAILS\FOLDER\%f_thumb.%e" "PATH\TO\IMAGES\FOLDER"

`
Thanks again for your help and to Phil Harvey for creating this powerful program.

StarGeek

Quote from: Athelstan on November 16, 2023, 12:05:40 PMSwitched slashes to backslashes for use on Windows11.

You can use either slashes or backslashes in a file path.  Exiftool is written in Perl and it will automatically convert backslashes to slashes.

You can see this by looking at the Directory tag.
C:\>exiftool -Directory Y:\!temp\x\y\ 
======== Y:/!temp/x/y/REC_0027.AVI
Directory                      : Y:/!temp/x/y
======== Y:/!temp/x/y/test1.jpg
Directory                      : Y:/!temp/x/y
======== Y:/!temp/x/y/test2.jpg
Directory                      : Y:/!temp/x/y
    1 directories scanned
    3 image files read

It's not going to affect your command but it needs to be taken into account when doing any comparisons with a file path.
"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