OpenAI: scale images

This commit is contained in:
M66B
2024-05-14 21:30:08 +02:00
parent 32964f1edd
commit 73097569f5
2 changed files with 25 additions and 12 deletions

View File

@@ -617,18 +617,22 @@ class ImageHelper {
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();
return getDataUri(is, type);
}
}
static String getDataUri(InputStream is, String type) throws IOException {
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" +