OpenAI: Images, Edit Specific Area
Completes the transparent areas of an original image with a PROMPT, by default 1024×1024. The areas to be edited can also be specified in another file. The given image must be square less than 4MB. The maximum number created at once is 10.
Configs for this Auto Step
- AuthzConfU1
- U1: Select HTTP_Authz Setting (Secret API Key as “Fixed Value”) *
- StrConfA0
- A0: Set Request Message PROMPT *#{EL}
- SelectConfA1
- A1: Select FILE in which Original Image stored *
- SelectConfA1b
- A1b: To Specify Edit Area in Another File, Select FILE
- SelectConfB1
- B1: Select FILE that stores Created Images (update)
- StrConfU2
- U2: Set OpenAI Organization ID (“org-xxxx”)#{EL}
- StrConfU3
- U3: Set End-User ID for Monitoring or Detecting (“user123456”)#{EL}
- StrConfA2
- A2: Set NUMBER of Images to Generate (1 to 10)#{EL}
- StrConfA3
- A3: Set SIZE (“256×256”, “512×512”, or “1024×1024”)#{EL}
- SelectConfB2
- B2: Select FILE that stores Generated Images (append)
- StrConfC1
- C1: To save-as, Set new File Names (new line delimited)#{EL}
Script (click to open)
// GraalJS Script (engine type: 2)
//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){
////// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting = configs.get( "AuthzConfU1" ); /// REQUIRED
engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strOrgId = configs.get( "StrConfU2" ); // NotRequired
engine.log( " AutomatedTask Config: OpenAI-Organization: " + strOrgId );
const strEndUserId = configs.get( "StrConfU3" ) !== "" ? // NotRequired
configs.get( "StrConfU3" ) :
"m" + processInstance.getProcessModelInfoId().toString(); // (default)
engine.log( " AutomatedTask Config: End User IDs: " + strEndUserId );
const strPrompt = configs.get( "StrConfA0" ); /// REQUIRED
if( strPrompt === "" ){
throw new Error( "\n AutomatedTask ConfigError:" +
" Config {A0: Prompt} must be non-empty \n" );
}
const filesPocketOriginal = configs.getObject( "SelectConfA1" ); /// REQUIRED
let filesOriginal = engine.findData( filesPocketOriginal ); // java.util.ArrayList
if( filesOriginal === null ){
throw new Error( "\n AutomatedTask ConfigError:" +
" Config {A1: OriginalFile} must be non-empty \n" );
}
engine.log( " AutomatedTask Config: #of Original Files: " + filesOriginal.size() );
engine.log( " AutomatedTask Config: Original Image File: " + filesOriginal.get(0).getName() );
const filesPocketMask = configs.getObject( "SelectConfA1b" ); // NotRequired
let filesMask = filesPocketMask !== null ?
engine.findData( filesPocketMask ) : null;
if( filesMask === null ){
engine.log( " AutomatedTask Config: No Mask file used" );
} else {
engine.log( " AutomatedTask Config: Mask Image File: " + filesMask.get(0).getName() );
}
const strGenerate = configs.get( "StrConfA2" ); // NotRequired
const numGenerate = isNaN( parseInt(strGenerate,10) ) ? 1 : parseInt(strGenerate,10);
const strSize = configs.get( "StrConfA3" ) !== "" ? // NotRequired
configs.get( "StrConfA3" ) : "1024x1024"; // (default)
const filesPocketUpdate = configs.getObject( "SelectConfB1" ); // NotRequired
let filesUpdate = new java.util.ArrayList();
const filesPocketAppend = configs.getObject( "SelectConfB2" ); // NotRequired
let filesAppend = new java.util.ArrayList();
if ( filesPocketAppend !== null ) {
if ( engine.findData( filesPocketAppend ) !== null ) {
filesAppend = engine.findData( filesPocketAppend ); // java.util.ArrayList
engine.log( " AutomatedTask FilesArray {B2}: " +
filesAppend.size() + " files" );
}
}
const strFileNames = configs.get( "StrConfC1" ); // NotRequired
const arrFileNames = strFileNames === "" ?
[] : strFileNames.split( '\n' );
////// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)
////// == Calculating / 演算 ==
//// OpenAI API > Documentation > API REFERENCE > IMAGES > Create image edit
//// https://platform.openai.com/docs/api-reference/images/create-edit
/// prepare request1
let request1Uri = "https://api.openai.com/v1/images/edits";
let request1 = httpClient.begin(); // HttpRequestWrapper
request1 = request1.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
if ( strOrgId !== "" ){
request1 = request1.header( "OpenAI-Organization", strOrgId );
}
/// prepare multipart/form-data
request1 = request1.multipart ( "prompt", strPrompt );
request1 = request1.multipart ( "n", numGenerate.toString() );
request1 = request1.multipart ( "size", strSize );
request1 = request1.multipart ( "response_format", "url" );
request1 = request1.multipart ( "user", strEndUserId );
request1 = request1.multipart ( "image", filesOriginal.get(0) );
if ( filesMask !== null ){
request1 = request1.multipart ( "mask", filesMask.get(0) );
}
/// try request1
const response1 = request1.post( request1Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + ""; // JavaNum to string
const response1Body = response1.getResponseAsString();
engine.log( " AutomatedTask ApiResponse1 Status: " + response1Code );
if( response1Code !== "200"){
throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
response1Code + "\n" + response1Body + "\n" );
}
engine.log( response1Body ); // debug★★★
/// parse response1
/* engine.log( response1Body ); // debug
{
"created": 1683701883,
"data": [
{
"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-sWMNKIpK"
},
{
"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-sWMNKIpK"
},
{
"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-sWMNKIpK"
},
{
"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-sWMNK..."
}
]
}
*/
const response1Obj = JSON.parse( response1Body );
engine.log( " AutomatedTask OpenAI #created: " + response1Obj.created );
for ( let i = 0; i < response1Obj.data.length; i++ ) {
/// prepare request2
let request2Uri = response1Obj.data[i].url;
let request2 = httpClient.begin(); // HttpRequestWrapper
/// try request2i
const response2 = request2.get( request2Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest2 Start: " + request2Uri );
const response2Code = response2.getStatusCode() + ""; // JavaNum to string
engine.log( " AutomatedTask ApiResponse2 Status: " + response2Code );
if( response2Code !== "200"){
throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
response2Code + "\n" + response2.getResponseAsString() + "\n" );
}
/* // debug
let jarrHeaders = response2.getHeaderNames();
for ( let j = 0; j < jarrHeaders.size() - 0 ; j++ ) {
engine.log( " " + jarrHeaders.get(j) );
}
Content-Length
Content-Type
Content-MD5
Last-Modified
Accept-Ranges
ETag
Server
x-ms-request-id
x-ms-version
x-ms-creation-time
x-ms-lease-status
x-ms-lease-state
x-ms-blob-type
Content-Disposition
x-ms-server-encrypted
Date
*/
/// save file
let strName = arrFileNames[i] ?? "";
if ( strName === "" ) {
strName = processInstance.getProcessInstanceId().toString() +
"-" + i + ".png";
}
const qfileTmp = new com.questetra.bpms.core.event.scripttask.NewQfile(
strName, response2.getContentType(), response2.getResponse()
);
// NewQfile ( stringFileName, stringContentType, ByteArray )
filesUpdate.add( qfileTmp );
filesAppend.add( qfileTmp );
}
////// == Data Updating / ワークフローデータへの代入 ==
if( filesPocketUpdate !== null ){
engine.setData( filesPocketUpdate, filesUpdate );
}
if( filesPocketAppend !== null ){
engine.setData( filesPocketAppend, filesAppend );
}
} //////// END "main()" /////////////////////////////////////////////////////////////////
/*
Notes:
- If you place this "Automated Step" in the Workflow diagram, the request will be automatically sent every time the process token arrives.
- A request is automatically sent to the OpenAI API server. (REST API)
- The response from the OpenAI API server is automatically parsed.
- You can incorporate "AI assistance" into your business processes.
- This "Automated Step" accesses the image generation engine "DALL-E 2" Model. (as of 2023)
- The maximum number of images that can be generated is 10.
- Automate various AI image editing.
- Correcting photos with imperfections
- Change facial expressions of character illustrations
APPENDIX
- To activate a Workflow App that includes this Automated Step, "HTTP Authz Setting" is required
- Obtain a "Secret API Key" in advance.
- Set the key as the communication token in "Token Fixed Value"
- If multiple images are stored, the first file will be considered the original image.
- The file must be a valid PNG file. (RGB mode, RGBA mode)
- The file must be a perfect square.
- To specify the area to be edited in another file (Mask Image)
- Must be the same size
- e.g. `"Invalid input mask - mask size must match image size 1200x1200, got 1024x1024 instead."`
- Must contain transparent areas
- Transparent PNG Examples
- square1024-top-transparent.png
- square1024-bottom-transparent.png
- square1024-right-transparent.png
- square1024-left-transparent.png
- square1024-center-transparent.png
Notes-ja:
- この[自動工程]をワークフロー図に配置すれば、案件が到達する度にリクエストが自動送信されます。
- OpenAI API サーバに対してリクエストが自動送出されます。(REST API通信)
- OpenAI API サーバからのレスポンスが自動保存解析されます。
- "AI による支援" を業務プロセスに組み込むことが出来ます。
- この[自動工程]は、画像生成エンジン "DALL-E 2" Model にアクセスします。(2023現在)
- 一度に生成できる画像は、最大で10個です。
- さまざまAI画像編集を自動化できます。
- 写り込みがある写真の補正
- キャラクターイラストの表情変更
APPENDIX-ja
- この[アドオン自動工程]を含むワークフローアプリを運用するには[HTTP 認証設定]が必要です。
- あらかじめ "Secret API Key" を取得しておいてください。
- "Secret API Key" を通信トークンとしてセットします。[トークン直接指定]
- 複数画像が格納されている場合、第1番目のファイルをオリジナル画像とみなします。
- 当該ファイルは、PNG形式でなければなりません。(RGBモード、RGBAモード)
- 当該ファイルは、完全な正方形でなければなりません。
- 編集領域を別ファイル(マスク画像)で指定する場合:
- 同じサイズでなければなりません
- e.g. `"Invalid input mask - mask size must match image size 1200x1200, got 1024x1024 instead."`
- 透明な領域を含まなければなりません
- 透過 PNG サンプル
- square1024-top-transparent.png
- square1024-bottom-transparent.png
- square1024-right-transparent.png
- square1024-left-transparent.png
- square1024-center-transparent.png
*/
Download
- openai-images-edit-specific-area-2023.xml
- 2023-05-15 (C) Questetra, Inc. (MIT License)
(Installing Addon Auto-Steps are available only on the Professional edition.)
Notes
- If you place this Automated Step in a Workflow diagram, the request will be automatically sent every time the process token arrives.
- A request is automatically sent to the OpenAI API server. (REST API)
- The response from the OpenAI API server is automatically parsed.
- You can incorporate AI assistance into your business processes.
- This Automated Step accesses the image generation engine “DALL-E 2” Model. (as of 2023)
- The maximum number of images that can be generated is 10.
- Automate various AI image editing.
- Correcting photos with imperfections
- Change facial expressions of character illustrations
Capture



Appendix
- To activate a Workflow App that includes this Automated Step, “HTTP Authz Setting” is required
- Obtain a “Secret API Key” in advance.
- Set the key as the communication token in “Token Fixed Value”
- If multiple images are stored, the first file will be considered the original image.
- The file must be a valid PNG file. (RGB mode, RGBA mode)
- The file must be a perfect square.
- To specify the area to be edited in another file (Mask Image)
- Must be the same size
- e.g.
"Invalid input mask - mask size must match image size 1200x1200, got 1024x1024 instead."
- e.g.
- Must contain transparent areas
- Must be the same size