Converts an image to a Base64 string.
Syntax
text AI_ImageAsBase64 (bytea image, boolean mime_type DEFAULT true)
Parameters
|
Parameter |
Description |
|
image |
The image data represented in binary format. |
|
mime_type |
The MIME type. Valid values:
Note
For more information about MIME types, see community documentation. |
Return value
Returns the Base64 string of the converted image.
Description
-
JPEG, PNG, and BMP image formats are supported.
-
AI models typically have specific size requirements for input images, but common images tend to have large pixel dimensions. You can use the AI_ResizeImage function to resize the image to the required dimensions, and then use this function to convert it to a Base64 string.
Example
SELECT AI_ImageAsBase64(data) FROM ai_image_test WHERE id = 1;
Sample output:
---
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD...