ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: dwlott on January 31, 2024, 10:57:19 AM

Title: How do I set a thumbnail image into similar-named files?
Post by: dwlott on January 31, 2024, 10:57:19 AM
Hello again,
How do I set a thumbnail image into similar-named files in a different folder? 

For example, I want File01_thumb.jpg to be the ThumbnailImage for its like-named file in the target folder, minus the "_thumb" part of the source file name.  The following code is missing parse for the "_thumb" and might have other problems. 

-ThumbnailImage<=
E:\mySourceFolder\extract\File01_thumb.jpg
-srcfile
e:\myTargetFolder\%f.%e


I also want to know how to set a thumbnail image into like-named files in the same folder.

I know this code has problems, but I'm including it to help illustrate what I'm trying to do and that I'm using an args file.

-ThumbnailImage<=
E:\mySourceFolder\extract\File01_thumb.jpg
-srcfile

Thanks for your help, as always.


Title: Re: How do I set a thumbnail image into similar-named files?
Post by: StarGeek on January 31, 2024, 11:47:14 AM
I'm a bit confused about what directory you are processing, but I think I can give some examples

This will embed the thumbnails from "mySourceFolder" into the files in "myTargetFolder"
exiftool "-ThumbnailImage<=E:\mySourceFolder\extract\%f_thumb.jpg" e:\myTargetFolder\

In this case, it takes the base filename in "myTargetFolder", appends "_thumb", and looks for the thumb in "mySourceFolder"

Using the -srcfile option (https://exiftool.org/exiftool_pod.html#srcfile-FMT).  At least I think it will work.  IMO, you are introducing unneeded complexity with the use of -srcfile.
exiftool "-ThumbnailImage<=E:\mySourceFolder\extract\%f.%e" -srcfile e:\myTargetFolder\%-.6f.%e E:\mySourceFolder\extract\

Here I'm taking the name of the thumb in "mySourceFolder", removing the last six characters of the base filename, i.e. removing "_thumb", and looking in "myTargetFolder" for the file to embed i.e. the srcfile.  Then back to the original name for the <=.

Though
"-ThumbnailImage<=E:\mySourceFolder\extract\%f.%e"
probably should be replaced by
"-ThumbnailImage<=%d%f.%e"
Title: Re: How do I set a thumbnail image into similar-named files?
Post by: dwlott on February 07, 2024, 01:51:02 PM
-ThumbnailImage<=
E:\mySourceFolder\extract\%f_thumb.jpg
E:\myTargetFolder\

As you suggested, StarGeek, I found the above best for my needs in setting ThumbnailImage into similar-named files in a different folder.

With that knowledge, I found that the following code works for write the folder of images to the ThumbnailImage of files of a different extension. Note that the .orf extension is specified in the command. 

-PreviewImage<=E:\mySourceFolder\extract\%f_thumb.jpg
e:\myTargetFolder\*.orf

Now, I want to include like-named subfolders.  I have a tree of thumbnails that I want to set into an identical tree of images, the file names similar, as we have been working on in this thread.

I am trying this string %:3d in the destination line as shown in this code:

-r
-PreviewImage<=E:\mySourceFolder\extract\%f_thumb.jpg
e:\myTargetFolder\%:3d*.orf

exiftool replies "No matching files"

Thank you again for your help.

 
Title: Re: How do I set a thumbnail image into similar-named files?
Post by: Phil Harvey on February 07, 2024, 09:25:23 PM
Quote from: dwlott on February 07, 2024, 01:51:02 PM-r
-PreviewImage<=E:\mySourceFolder\extract\%f_thumb.jpg
e:\myTargetFolder\%:3d*.orf

exiftool replies "No matching files"

You can't use % codes in the target file name.  I don't understand what you are trying to do.  Can you give examples of a few target file names the the corresponding thumbnail names?

- Phil
Title: Re: How do I set a thumbnail image into similar-named files?
Post by: StarGeek on February 07, 2024, 11:43:34 PM
Quote from: dwlott on February 07, 2024, 01:51:02 PMWith that knowledge, I found that the following code works for write the folder of images to the ThumbnailImage of files of a different extension. Note that the .orf extension is specified in the command. 

-PreviewImage<=E:\mySourceFolder\extract\%f_thumb.jpg
e:\myTargetFolder\*.orf

Now, I want to include like-named subfolders.

You can't use a wildcard and recurse into subdirectories.  You need to use the -ext (-extension) option (https://exiftool.org/exiftool_pod.html#ext-EXT---ext-EXT--extension) to limit the types of files to process.

See Common Mistake #2 (https://exiftool.org/mistakes.html#M2) and the -r (-recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse).

The files that are in e:\myTargetFolder\ are the base file paths.  What you want to do is take that base path, edit it using %d so that it matches the locations in E:\mySourceFolder\extract\.

What I think you want is
-PreviewImage<=E:\mySourceFolder\extract\%:2d%f_thumb.jpg

This takes the directory path of the ORF file, removes the top two directories, in this case e:\myTargetFolder\ and append what remains after E:\mySourceFolder\extract\.

For example, you have two files
e:\myTargetFolder\File_1.orf
e:\myTargetFolder\SubDir\SubFile_1.orf

Using %:2d would remove e:\myTargetFolder from both of these filepaths, leaving File_1.orf with no directory path included and SubFile_1.orf with a SubDir\.

These directory paths are then appended to E:\mySourceFolder\extract\ giving you
E:\mySourceFolder\extract\
E:\mySourceFolder\extract\SubDir\

Then the %f base filename is added
E:\mySourceFolder\extract\File_1
E:\mySourceFolder\extract\SubDir\SubFile_1

And then finally _thumb.jpg appended, telling exiftool to look for these file to embed in the original ORF files
E:\mySourceFolder\extract\File_1_thumb.jpg
E:\mySourceFolder\extract\SubDir\SubFile_1_thumb.jpg
Title: Re: How do I set a thumbnail image into similar-named files?
Post by: dwlott on February 11, 2024, 11:39:13 AM
Thank you, guys; I am learning from what you wrote, but please help me further in reading and writing binaries to and from like-named files. 

I aim to extract thumbnails to a thumbnail folder, keeping the directory structure, and with another command, write them back from where they came.

For clarity, I am working in different folders now as shown in the screenshots below.

When I run the following command to extract thumbnails, the thumbnails are saved correctly and structured in the destination folders, but Exiftool returns error messages.  I want to use the best command to avoid the error messages.  Also, please help me with the command for writing the thumbnails back to their original files.

-r
-JpgFromRaw
-ThumbnailImage
E:\images
-a
-b
-W
E:\thumbs\%:2d%f.%s

ExifTool reply:
QuoteOutput file E:/thumbs/File01_thumb.jpg already exists for E:/images/File01.ORF
Output file E:/thumbs/File02_thumb.jpg already exists for E:/images/File02.ORF
Output file E:/thumbs/File03_thumb.jpg already exists for E:/images/File03.ORF
Output file E:/thumbs/File04_thumb.jpg already exists for E:/images/File04.ORF
    2 directories scanned
    1 directories created
    9 image files read
    4 files could not be read
    9 output files created

The thumbs folder is known empty when I run the command. I've been experimenting for a few hours.

Here is a screenshot of the images folder.
(https://davelott.com/wp-content/uploads/2024/02/SourceFolder.jpg)

Here is a screenshot of the images sub folder.
(https://davelott.com/wp-content/uploads/2024/02/SourceSubFolder.jpg)

Here is a screenshot of the thumbnail folder.
(https://davelott.com/wp-content/uploads/2024/02/TargetFolder.jpg)

Here is a screenshot of the thumbnail sub folder.
(https://davelott.com/wp-content/uploads/2024/02/ThumbnailFolderSubs.jpg)

Title: Re: How do I set a thumbnail image into similar-named files?
Post by: Phil Harvey on February 11, 2024, 01:00:11 PM
Your command is writing both JpgFromRaw and ThumbnailImage to the same file name, which is why you only get one, and why you get an error message for the other.  The best way to separate them is to add %t (the tag name) to the output file name, like this to add the tag name to the file name:

-W
E:/thumbs/%:2d%f_%t.%s

or like this to put them in a separate directory:

-W
E:/thumbs/%:2d%t/%f.%s

- Phil

Title: Re: How do I set a thumbnail image into similar-named files?
Post by: dwlott on February 11, 2024, 04:11:10 PM
Thank you, Phil,
I adjusted the command by removing the 2nd tag and using the %t option.  The thumbnails are produced, but there are error messages in the ExifTool reply.  See below the command I am trying, the ExifTool reply, and the thumbnail files produced.

-r
-ThumbnailImage
E:\images
-a
-b
-W
E:\thumbs\%:2d%f_%t.%s

QuoteOutput file E:/thumbs/File01_ThumbnailImage.jpg already exists for E:/images/File01.ORF
Output file E:/thumbs/File02_ThumbnailImage.jpg already exists for E:/images/File02.ORF
Output file E:/thumbs/File03_ThumbnailImage.jpg already exists for E:/images/File03.ORF
Output file E:/thumbs/File04_ThumbnailImage.jpg already exists for E:/images/File04.ORF
    2 directories scanned
    1 directories created
    9 image files read
    4 files could not be read
    9 output files created
(https://davelott.com/wp-content/uploads/2024/02/newThumbnailFolderSubs.jpg)
Title: Re: How do I set a thumbnail image into similar-named files?
Post by: StarGeek on February 11, 2024, 08:25:21 PM
There are probably multiple ThumbnailImage in the file.  Add a copy number %c to the thumb filename.
Title: Re: How do I set ThumbnailImage into similar-named files?
Post by: dwlott on February 13, 2024, 09:14:24 AM
Please help further with a command that will set a tree of thumbnails into an identical tree of images. 
e:\thumbs
   has files like: file01_ThumbnailImage.jpg, file02_ThumbnailImage.jpg
   (with subfolders)
e:\images
   has files like: file01.jpg, file02.jpg
   (with subfolders)

Title: Re: How do I set a thumbnail image into similar-named files?
Post by: StarGeek on February 13, 2024, 12:07:03 PM
Just add the text to the proper place in the format string. For example, above I suggested
%:2d%f_thumb.jpg
instead of "_thumb", you would use "_ThumbnailImage"
%:2d%f_ThumbnailImage.jpg
Title: Re: How do I set a thumbnail image into similar-named files?
Post by: dwlott on February 13, 2024, 01:03:09 PM
I think that I am getting closer.  Please help me include the subfolders.
This command updates the files in e:\images, but not the files in e:\images\subs
-r
-ThumbnailImage<=E:\thumbs\%:2d%f_ThumbnailImage.jpg
E:\images\*.orf

ExifTool reply:
Quote4 image files updated
Title: Re: How do I set a thumbnail image into similar-named files?
Post by: Phil Harvey on February 13, 2024, 01:09:59 PM
This is Common Mistake 2c (https://exiftool.org/mistakes.html#M2), which StarGeek already mentioned in his post above.

Try this:

-r
-ThumbnailImage<=E:\thumbs\%:2d%f_ThumbnailImage.jpg
-ext
orf
E:\images

- Phil
Title: Re: How do I set a thumbnail image into similar-named files?
Post by: dwlott on February 13, 2024, 03:01:17 PM
There it is!  Thank you Phil.  I'm catching on.