How can I adjust image quality/dpi without changing pixel size?
I have an image with a specific pixel size that I need to reduce in quality before saving. If I want to decrease the quality to 87%, how do I achieve this using the following functions?
function defineNewImgFile(image) {
let imgBlob = base64ImageToBlob(image);
let newFile = new File([imgBlob], image, {
type: typeOfImg
});
return newFile;
}
//changes base64 format
let typeOfImg;
function base64ImageToBlob(str) {
let pos = str.indexOf(';base64,');
let type = str.substring(5, pos);
typeOfImg = type;
let b64 = str.substr(pos + 8);
let imageContent = atob(b64);
let buffer = new ArrayBuffer(imageContent.length);
let view = new Uint8Array(buffer);
for (let n = 0; n < imageContent.length; n++) {
view[n] = imageContent.charCodeAt(n);
}
let blob = new Blob([view], {
type: type
});
return blob;
}