Skip to main content
Version: Next

OpenAIImage

The OpenAIImage class represents an image generated by the OpenAI API. It provides properties for accessing the generated image in different formats and methods for converting this image to different types.

https://platform.openai.com/docs/api-reference/images/object

Properties

PropertyTypeDescription
urlTextThe URL of the generated image, if response_format is url (default).
b64_jsonTextThe base64-encoded JSON of the generated image, if response_format is b64_json.
revised_promptVariantThe prompt that was used to generate the image, if there was any revision to the prompt.

Functions

asBlob()

asBlob() : 4D.Blob

| Function result| 4D.Blob | Converts the generated image to a blob format based on its URL or base64-encoded JSON. |

Example Usage

var $blob:=$image.asBlob()

asPicture()

asPicture() : Picture

| Function result| Picture | Creates a picture object from the blob converted image. |

Example Usage

var $picture:=$image.asPicture()

saveToDisk()

saveToDisk(file : 4D.File) : Boolean

ParameterTypeDescription
file4D.FileThe file object where the image will be saved.
Function resultBooleanReturns True if the image is successfully saved.

Saves the image to disk, attempting to download it first if it is a URL. Returns False if it could not retrieve the image data.

Example Usage

var $success:=$image.saveToDisk(Folder(fk desktop folder).file("image.png"))