Skip to content

Commit

Permalink
compress uploaded images when on cellular
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Sep 12, 2023
1 parent f90cc0b commit daf4e7e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ async function handleFiles(files, mediaArray, mediaContainer) {
videos.push(file);
} else if (file.type.includes('image')) {
// max 5 mb
if (file.size > 5000000) {
if (
file.size > 5000000 ||
(window.navigator && navigator.connection && navigator.connection.type === 'cellular' && !vars.disableDataSaver)
) {
// convert png to jpeg
await new Promise(resolve => {
let canvas = document.createElement('canvas');
Expand All @@ -86,7 +89,7 @@ async function handleFiles(files, mediaArray, mediaContainer) {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
let dataURL = canvas.toDataURL('image/jpeg', 0.9);
let dataURL = canvas.toDataURL('image/jpeg', (window.navigator && navigator.connection && navigator.connection.type === 'cellular' && !vars.disableDataSaver) ? 0.5 : 0.9);
let blobBin = atob(dataURL.split(',')[1]);
let array = [];
for (let i = 0; i < blobBin.length; i++) {
Expand Down

0 comments on commit daf4e7e

Please sign in to comment.