OpenAI: image support

This commit is contained in:
M66B
2024-05-14 20:21:54 +02:00
parent 229a45d87b
commit 252ad4c2a5
4 changed files with 66 additions and 23 deletions

View File

@@ -615,6 +615,20 @@ class ImageHelper {
return source.substring(colon + 1, semi);
}
static String getDataUri(File file, String type) throws IOException {
try (InputStream is = new FileInputStream(file)) {
byte[] bytes = Helper.readBytes(is);
StringBuilder sb = new StringBuilder();
sb.append("data:");
sb.append(type);
sb.append(";base64,");
sb.append(Base64.encodeToString(bytes, Base64.NO_WRAP));
return sb.toString();
}
}
static ByteArrayInputStream getDataUriStream(String source) {
// "<img src=\"data:image/png;base64,iVBORw0KGgoAAA" +
// "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +