Merge branch 'resize-blob' into 'develop'
Fix .blob extension in uploaded files Closes #617 See merge request soapbox-pub/soapbox-fe!479
This commit is contained in:
commit
78f9807b22
1 changed files with 8 additions and 4 deletions
|
@ -42,7 +42,7 @@ const getOrientation = (img, type = 'image/png') => new Promise(resolve => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const processImage = (img, { width, height, orientation, type = 'image/png' }) => new Promise(resolve => {
|
const processImage = (img, { width, height, orientation, type = 'image/png', name = 'resized.png' }) => new Promise(resolve => {
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
|
|
||||||
if (4 < orientation && orientation < 9) {
|
if (4 < orientation && orientation < 9) {
|
||||||
|
@ -67,11 +67,14 @@ const processImage = (img, { width, height, orientation, type = 'image/png' }) =
|
||||||
|
|
||||||
context.drawImage(img, 0, 0, width, height);
|
context.drawImage(img, 0, 0, width, height);
|
||||||
|
|
||||||
canvas.toBlob(resolve, type);
|
canvas.toBlob((blob) => {
|
||||||
|
resolve(new File([blob], name));
|
||||||
|
}, type);
|
||||||
});
|
});
|
||||||
|
|
||||||
const resizeImage = (img, type = 'image/png') => new Promise((resolve, reject) => {
|
const resizeImage = (img, inputFile) => new Promise((resolve, reject) => {
|
||||||
const { width, height } = img;
|
const { width, height } = img;
|
||||||
|
const type = inputFile.type || 'image/png';
|
||||||
|
|
||||||
const newWidth = Math.round(Math.sqrt(MAX_IMAGE_PIXELS * (width / height)));
|
const newWidth = Math.round(Math.sqrt(MAX_IMAGE_PIXELS * (width / height)));
|
||||||
const newHeight = Math.round(Math.sqrt(MAX_IMAGE_PIXELS * (height / width)));
|
const newHeight = Math.round(Math.sqrt(MAX_IMAGE_PIXELS * (height / width)));
|
||||||
|
@ -80,6 +83,7 @@ const resizeImage = (img, type = 'image/png') => new Promise((resolve, reject) =
|
||||||
.then(orientation => processImage(img, {
|
.then(orientation => processImage(img, {
|
||||||
width: newWidth,
|
width: newWidth,
|
||||||
height: newHeight,
|
height: newHeight,
|
||||||
|
name: inputFile.name,
|
||||||
orientation,
|
orientation,
|
||||||
type,
|
type,
|
||||||
}))
|
}))
|
||||||
|
@ -99,7 +103,7 @@ export default inputFile => new Promise((resolve, reject) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeImage(img, inputFile.type)
|
resizeImage(img, inputFile)
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(() => resolve(inputFile));
|
.catch(() => resolve(inputFile));
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
|
|
Loading…
Reference in a new issue