if a png image is too big even after scaling, convert it to jpeg

This commit is contained in:
or-else
2018-08-21 11:53:03 +03:00
parent c7325e3c25
commit aca9286d63
2 changed files with 6 additions and 3 deletions
+5 -2
View File
@@ -117,12 +117,12 @@ function fitImageSize(width, height, maxWidth, maxHeight, forceSquare) {
maxWidth = maxHeight = Math.min(maxWidth, maxHeight);
}
var scale = Math.min(
let scale = Math.min(
Math.min(width, maxWidth) / width,
Math.min(height, maxHeight) / height
);
var size = {
let size = {
dstWidth: (width * scale) | 0,
dstHeight: (height * scale) | 0,
};
@@ -206,6 +206,9 @@ function imageFileScaledToBase64(file, width, height, forceSquare, onSuccess, on
}
// Ensure the image is not too large
var quality = 0.78;
if (base64DecodedLen(imageBits.length) > MAX_INBAND_ATTACHMENT_SIZE) {
mime = "image/jpeg";
}
if (mime == "image/jpeg") {
// Reduce size of the jpeg by reducing image quality
while (base64DecodedLen(imageBits.length) > MAX_INBAND_ATTACHMENT_SIZE && quality > 0.45) {
+1 -1
View File
File diff suppressed because one or more lines are too long