Replacing metadata phrases for AI-generated images

Started by Chika_K, April 18, 2023, 11:26:38 AM

Previous topic - Next topic

Chika_K

Hello,

I am uploading AI-generated images to several stock photo sites, and each site has different recommended phrases to include in the metadata titles and descriptions related to AI. I would like to use ExifTool to search and replace these phrases in the metadata (titles and descriptions) of the jpg images.

Currently, I have metadata files with the following format:
Title: [Title]. Generative AI.
Description: [Description]. Created using Generative AI and image editing software.

Here, [Title] and [Description] represent unique text for each image, such as:
Title: [Tulips in a field]. Generative AI.
Description: [In the warm sunlight of Lisse, the Netherlands, a field of tulips unfolds in vibrant colors]. Created with Generative AI and image editing software.

I want to batch replace these files with the following metadata format:
Title: [Title]. AI Generated.
Description: [Description]. Created using AI Generated technology and image editing software.

I asked GPT-4 for help and it suggested the following commands:

For searching and replacing titles:
exiftool -ext jpg -if "$IPTC:ObjectName=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated/" -P -IPTC:ObjectName<${IPTC:ObjectName} -overwrite_original .

For searching and replacing descriptions:
exiftool -ext jpg -if "$IPTC:Caption-Abstract=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated technology/" -P -IPTC:Caption-Abstract<${IPTC:Caption-Abstract} -overwrite_original .

However, when I actually execute these commands, I get an error message in Japanese that says "指定されたファイルが見つかりません", which translates to "The specified file cannot be found".

Can ExifTool do what I want to do? If there is an error in the command, how can I fix it?

I am not a native English speaker, so I apologize if there are any unnatural expressions in my writing.

Thank you,

Chika_K

Phil Harvey

Hi Chika,

What command shell are you using?  Windows CMD?

The quoting is different depending on the shell you are using.

Also, you'll have to determine what ExifTool tag names to use.  See FAQ 2 and 3 for this.  ChatGPT is using IPTC:Caption-Abstract and IPTC:ObjectName, but I would think XMP:Title and XMP:Description would be more likely.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Chika_K

#2
Hi Phil,

Thank you for your prompt reply.
I'm using Windows Command Prompt and have also checked FAQ 2 and 3 in the link you provided.
Based on your suggestions, I changed the metadata tags from IPTC to XMP.
Specifically, I changed the title from IPTC:ObjectName to XMP:Title and the description from IPTC:Caption-Abstract to XMP:Description.

Here are the updated commands I used:

exiftool -ext jpg -if "$XMP:Title=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated/" -P -XMP:Title<${XMP:Title} -overwrite_original .
exiftool -ext jpg -if "$XMP:Description=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated technology/" -P -XMP:Description<${XMP:Description} -overwrite_original .


However, I still get the error message "指定されたファイルが見つかりません (The specified file cannot be found)".
I apologize for any inconvenience, but I would appreciate it if you could advise me on any other possible solutions to fix this problem.

Thank you for your help.

Best regards,

Chika

Phil Harvey

Hi Chika,

I should have realized earlier that this is a system error message.  The reason is probably because "exiftool.exe" is not in your PATH.

Try dragging and dropping "exiftool.exe" on the command window instead of just typing "exiftool".  This will enter the full path of the executable.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Chika_K

#4
Hi Phil,

Thank you for taking the time to advise me further.
I have followed your advice, but unfortunately the problem has not been resolved.
Below, I have summarized the steps I have tried and the current situation.

I tried to change the command prefix to "exiftool.exe" and executed the command, but I received an error message saying "The specified file could not be found (Japanese)".
I tried this for IPTC:ObjectName, IPTC:Caption-Abstract, XMP:Title, and XMP:Description, but the result was the same for all of them.

According to ChatGPT, any command starting with "exiftool" or "exiftool.exe" should work.
In particular, the following commands worked fine:

[sample commands].
exiftool -ver
exiftool.exe -ver
exiftool -r -ext jpg -XMP:Title -XMP:Description -IPTC:ObjectName -IPTC:Caption-Abstract "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\image
exiftool.exe -r -ext jpg -XMP:Title -XMP:Description -IPTC:ObjectName -IPTC:Caption-Abstract "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\image

Additionally, ChatGPT pointed out a potential problem with the "/" character within the regular expression pattern (I'm not exactly sure what it means).
However, after further discussion with ChatGPT, we concluded that the error was more likely due to other factors.

This is the current state of my situation.
I am not familiar with command line applications, so I may be missing something.

I apologize for the inconvenience, but would appreciate any further advice.

Best regards,

Chika

Phil Harvey

Did you drag and drop exiftool.exe onto the command window?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ryerman

#6
Quote from: Chika_K on April 19, 2023, 05:38:24 AMHere are the updated commands I used:

exiftool -ext jpg -if "$XMP:Title=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated/" -P -XMP:Title<${XMP:Title} -overwrite_original .
exiftool -ext jpg -if "$XMP:Description=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated technology/" -P -XMP:Description<${XMP:Description} -overwrite_original .


However, I still get the error message "指定されたファイルが見つかりません (The specified file cannot be found)".
Surround the assignment option with double quotes, like this:
exiftool -ext jpg -P "-XMP:Title<${XMP:Title}" "W:\path\to\Test.jpg"
That should prevent the "file not found" error.
But I suspect the -if option may not work as you expect.[/pre]

Windows 10 Home 64 bit, Exiftool v12.61

Chika_K

#7
Hi Phil,

I apologize for my earlier mistake.
I misunderstood the meaning of "drag and drop the 'exiftool.exe' onto the command window".
After I got it right, I tried the command suggested by ChatGPT.
Here is the command I used:

"C:\Program Files\ExifTool\exiftool.exe" -ext jpg -if "$xmp:title=~/Generative AI/" "-xmp:title=s/Generative AI/AI Generated/" -if "$xmp:description=~/Generative AI/" "-xmp:description=s/Generative AI/AI Generated technology/" "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\Image"

This command updated 15 image files in the specified directory.
However, contrary to my expectations, all the files ended up with the following titles and descriptions:

XMP:Title
s/Generative AI/AI Generated/

XMP:Description
s/Generative AI/AI Generated technology/

When I checked the specified directory, I found that new files with original metadata in the ".jpg_original" format were created for all 15 images.
ChatGPT suggested some other commands to fix this problem, but they all failed.

I apologize for the repeated inconvenience.
Could you please advise which command I should use to resolve this situation?
My expected result is to replace "Generative AI" with "AI Generated" in titles and replace "Generative AI" with "AI Generated technology" in descriptions.

Thank you in advance for your advice.

Chika

Chika_K

#8
Hi ryerman,

Thank you for your suggestion about the command.
I noticed that you had a message just as I was replying to Phil.

I replaced the file path as instructed and ran the command, which did indeed create files with the same name as the target files, but with the extension ".jpg_original" and a modified suffix.
However, when I checked the metadata, it remained unchanged.
I then asked ChatGPT for a revised command based on the original to replace the titles and descriptions.
Here are the suggested commands:

exiftool -ext jpg -if "$XMP:Title=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated/" -P "-XMP:Title<${XMP:Title}" "W:\path\to\your\files"

exiftool -ext jpg -if "$XMP:Description=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated technology/" -P "-XMP:Description<${XMP:Description}" "W:\path\to\your\files"

Unfortunately, these commands failed.
I apologize for any inconvenience caused by my lack of knowledge in using command line tools.
Thank you for your valuable input and help.

Chika

StarGeek

Quote from: Chika_K on April 20, 2023, 02:16:07 PMThis command updated 15 image files in the specified directory.
However, contrary to my expectations, all the files ended up with the following titles and descriptions:

XMP:Title
s/Generative AI/AI Generated/

XMP:Description
s/Generative AI/AI Generated technology/

This is Common Mistake #5c.  You used equal signs = when less than signs < are required to copy tags.

QuoteWhen I checked the specified directory, I found that new files with original metadata in the ".jpg_original" format were created for all 15 images.

From the docs, second paragraph under "Description"

    By default the original files are preserved with _original appended to their names -- be sure to verify that the new files are OK before erasing the originals.

You can suppress the creation of backup files by using the -overwrite_original option.


QuoteChatGPT suggested some other commands to fix this problem, but they all failed.

In what way did they fail.  It is impossible to help without knowing exactly what is going on.

Copy/paste the exact command and its exact output here so we can see.  Click and drag across the text to copy and then right click to copy the text to the clipboard.
"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

ryerman

Quote from: Chika_K on April 20, 2023, 02:16:59 PMexiftool -ext jpg -if "$XMP:Title=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated/" -P "-XMP:Title<${XMP:Title}" "W:\path\to\your\files"

exiftool -ext jpg -if "$XMP:Description=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated technology/" -P "-XMP:Description<${XMP:Description}" "W:\path\to\your\files"

Unfortunately, these commands failed.
Try this:
exiftool -ext jpg -overwrite_original "-XMP:Title<${XMP:Title;s/Generative AI/AI Generated/}" "-XMP:Description<${XMP:Description;s/Generative AI/AI Generated technology/}" "W:\path\to\your\files"
Windows 10 Home 64 bit, Exiftool v12.61

StarGeek

Quote from: Chika_K on April 20, 2023, 02:16:59 PMexiftool -ext jpg -if "$XMP:Title=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated/" -P "-XMP:Title<${XMP:Title}" "W:\path\to\your\files"

exiftool -ext jpg -if "$XMP:Description=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated technology/" -P "-XMP:Description<${XMP:Description}" "W:\path\to\your\files"

I see the problem now.  The -api Filter option changes the values of Title and Description.  And because of that, these tags will no longer contain "Generative AI" and the comparisons will always fail.  This can be fixed by adding the # shortcut for the -n (--printConv) option to the end of the tag names in the -if option.

Examples
Using the # to see what the results of the api option and the original values
C:\>exiftool -G1 -a -s -api "Filter=s/Generative AI/AI Generated technology/" -Title -Description -Title# -Description# y:\!temp\Test4.jpg
[XMP-dc]        Title                           : Title containing AI Generated technology.
[XMP-dc]        Description                     : Description containing AI Generated technology.
[XMP-dc]        Title                           : Title containing Generative AI.
[XMP-dc]        Description                     : Description containing Generative AI.

Working example
C:\>exiftool -G1 -a -s -Title -Description y:\!temp\Test4.jpg
[XMP-dc]        Title                           : Title containing Generative AI.
[XMP-dc]        Description                     : Description containing Generative AI.

C:\>exiftool -P -overwrite_original -if "$Title#=~/Generative AI/ or $Description#=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated/" "-XMP:Title<XMP:Title" "-XMP:Description<XMP:Description" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -Title -Description y:\!temp\Test4.jpg
[XMP-dc]        Title                           : Title containing AI Generated.
[XMP-dc]        Description                     : Description containing AI Generated.

The dollar signs $ were removed as they weren't needed in this case. It doesn't hurt the operation, only slowing it down by a few milliseconds.  See Common Mistake #5b.
"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

Chika_K

#12
Hi ryerman,

Thank you for your message.
I managed to get a successful command after having GPT-4 make several adjustments!
Here are the commands that worked:

exiftool -ext jpg -if "$xmp:title=/Generative AI/" -P "-xmp:title<${xmp:title;s/Generative AI/AI Generated/}" -overwrite_original "W:\path\to\your\files"
exiftool -ext jpg -if "$xmp:description=/Generative AI/" -P "-xmp:description<${xmp:description;s/Generative AI/AI Generated technology/}" -overwrite_original "W:\path\to\your\files"

According to GPT-4, these commands are very similar to the ones you provided.
I also tried your suggested commands, and they worked flawlessly as well.

GPT-4 explained that the two sets of commands differ in the presence or absence of the -if option for conditional branching.
However, in my case, I was working with a folder containing only JPEG files that met this specific condition, so both commands were successful.

I am grateful for your valuable advice.
Thank you for taking the time to help me.

Chika

Chika_K

#13
Hi StarGeek,

Thank you for your message.
Sorry if the translation below is not very good.
I had GPT-4 customize the command prompt based on the information you gave me and ran the following commands in the command prompt window with administrator privileges.

cd C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15
"C:\Program Files\ExifTool\exiftool.exe" -P -overwrite_original -if "$Title#=~/Generative AI/ or $Description#=~/Generative AI/" -api "Filter=s/Generative AI/AI Generated technology/" "-XMP:Title<XMP:Title" "-XMP:Description<XMP:Description" -ext jpg .

When I ran it, both the title and description became "AI Generated technology", but since all I needed was the title and description to include "AI Generated", I was successful here as well!
(This creates metadata for the image-generating AI that matches the rule names for each company on the stock site).

Title: [Title]. AI Generated technology.
Description: [Description]. Created using AI Generated technology and image editing software.
The metadata has been updated as described above.

I apologize for not giving you solid information, including details on how the prompt you requested from GPT-4 was changed.
From now on, I will tell you properly.

Each item is also listed below.
The OS is Windows 11.
The ExifTool version is 12.60.
The file type being processed is jpg.

Your suggestion to change the equal sign (=) to a minor sign (<) was invaluable in solving my problem.
Thank you very much.

Chika

Chika_K

#14
I am going to bed now, but in the case of this successful prompt, GPT-4 told us the following.

The successful command performs the search and replace operation in a variable as follows.

-xmp:title<${xmp:title;s/Generative AI/AI Generated/}
-xmp:description<${xmp:description;s/Generative AI/AI Generated technology/}

Here **`${}`** instructs ExifTool to perform string manipulation in the variable.
Specifically, the **`s/Generative AI/AI Generated/`** and **`s/Generative AI/AI Generated technology/`** parts are applied to the respective tag values to perform string substitution.

The format of a successful command has the following structure.

-xmp:tag name<${tag name;search and replace process}

By using this structure, ExifTool now updates the metadata correctly.

I wanted to look back at the commands so far and compare them side-by-side with the XMP:Title and XMP:Description commands I tried.
The same number of lines is actually what we went through when we executed the commands together.
The last four lines of each are the successful commands.

exiftool -ext jpg -if "$XMP:Title=~/Generative AI/" -api "Filter<s/Generative AI/AI Generated/" -P "-XMP:Title<${XMP:Title}" -overwrite_original "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15"
exiftool -ext jpg -if "$xmp:title=~/Generative AI/" -api "Filter<s/Generative AI/AI Generated/" -P "-xmp:title<${xmp:title}" -overwrite_original "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15"
exiftool -ext jpg -if "$xmp:title=~/Generative AI/" -P "-xmp:title=s/Generative AI/AI Generated/" -overwrite_original "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15"
exiftool -ext jpg -if "$xmp:title=~/Generative AI/" -P "-xmp:title<${xmp:title;s/Generative AI/AI Generated/}" -overwrite_original "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15"

exiftool -ext jpg -if "$XMP:Description=~/Generative AI/" -api "Filter<s/Generative AI/AI Generated technology/" -P "-XMP:Description<${XMP:Description}" -overwrite_original "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15"
exiftool -ext jpg -if "$xmp:description=~/Generative AI/" -api "Filter<s/Generative AI/AI Generated technology/" -P "-xmp:description<${xmp:description}" -overwrite_original "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15"
exiftool -ext jpg -if "$xmp:description=~/Generative AI/" -P "-xmp:description=s/Generative AI/AI Generated technology/" -overwrite_original "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15"
exiftool -ext jpg -if "$xmp:description=~/Generative AI/" -P "-xmp:description<${xmp:description;s/Generative AI/AI Generated technology/}" -overwrite_original "C:\Users\[MyUsername]\Pictures\Upload_AIGenerated\_15"

I solved this case because it was successful for me, but please let me know if there is anything else I can do for you after tomorrow.
I want to express my sincere appreciation for your support.