Tcl
Tcl
AI Modify Existing Image with Text Prompt
See more AI Examples
Uses an AI text prompt and uploaded image data to modify an existing image and receive the modified output.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
# Load the data from an existing image.
set bdImageData [new_CkBinData]
set success [CkBinData_LoadFile $bdImageData "qa_data/jpg/kid_blue_coat.jpg"]
if {$success == 0} then {
puts [CkBinData_lastErrorText $bdImageData]
delete_CkBinData $bdImageData
exit
}
set ai [new_CkAi]
CkAi_put_Provider $ai "openai"
# Use your provider's API key.
CkAi_put_ApiKey $ai "MY_API_KEY"
# Choose a model.
CkAi_put_Model $ai "gpt-5"
set askParams [new_CkJsonObject]
CkJsonObject_UpdateString $askParams "image.output_format" "jpeg"
CkAi_SetAskParams $ai $askParams
CkAi_InputAddImageData $ai $bdImageData ""
CkAi_InputAddText $ai "Modify the image by replacing the blue coat with a Metallica T-shirt."
# Give the AI some time (2 minutes).
CkAi_put_IdleTimeoutMs $ai 120000
# Ask the AI for image output.
set success [CkAi_Ask $ai "image"]
if {$success == 0} then {
puts [CkAi_lastErrorText $ai]
delete_CkBinData $bdImageData
delete_CkAi $ai
delete_CkJsonObject $askParams
exit
}
# Get the image response data.;
set success [CkAi_GetOutputBd $ai $bdImageData]
if {$success == 0} then {
puts [CkAi_lastErrorText $ai]
delete_CkBinData $bdImageData
delete_CkAi $ai
delete_CkJsonObject $askParams
exit
}
CkBinData_WriteFile $bdImageData "c:/aaworkarea/out.jpg"
puts "Success."
# -------------------------------
# Sample Input:
# -------------------------------
#
# -------------------------------
# Sample Output:
# -------------------------------
#
delete_CkBinData $bdImageData
delete_CkAi $ai
delete_CkJsonObject $askParams