Skip to content

Commit

Permalink
Merge pull request #16233 from schlawg/ui-crop-dialog-webp
Browse files Browse the repository at this point in the history
use webp for streamer, blog, coach, and tournament image uploads
  • Loading branch information
niklasf authored Oct 17, 2024
2 parents 678f3cb + 033afd5 commit 9ca8d94
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions ui/bits/src/bits.cropDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ export async function initModule(o?: CropOpts): Promise<void> {
maxWidth: opts.max?.pixels,
maxHeight: opts.max?.pixels,
});
const imgOutputFormat = isJpeg(opts.source) ? 'jpeg' : 'png';
const tryQuality = (quality = 1) => {
const tryQuality = (quality = 0.9) => {
canvas.toBlob(
blob => {
if (blob && blob.size < (opts.max?.megabytes ?? 100) * 1024 * 1024) submit(blob);
else if (blob && quality > 0.05) tryQuality(quality * 0.9);
else submit(false, 'Rendering failed');
},
`image/${imgOutputFormat}`,
`image/webp`,
quality,
);
};
Expand Down Expand Up @@ -155,9 +154,3 @@ export async function initModule(o?: CropOpts): Promise<void> {
return constrained;
}
}

const isJpeg = (source?: Blob | string) => {
if (source instanceof Blob) return source.type == 'image/jpeg';
if (typeof source == 'string') return /\.jpe?g$/i.test(source);
return false;
};

0 comments on commit 9ca8d94

Please sign in to comment.