mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-01 06:38:29 +02:00
OpenAI: image support
This commit is contained in:
@@ -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" +
|
||||
|
||||
Reference in New Issue
Block a user