Skip to content

Commit

Permalink
Cleanup -- removed offscreencanvas fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Sallaa committed Sep 5, 2024
1 parent e3bde72 commit 51da729
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/components/Shared/Utils/imageUtils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const resizeImage = async (imageData) => {
newWidth = newHeight * aspectRatio;
}

// Resize the image using an OffscreenCanvas (or fallback to regular canvas)
// Resize the image using an OffscreenCanvas
const resizedImageData = await resizeUsingCanvas(
imageBitmap,
newWidth,
Expand All @@ -72,22 +72,10 @@ export const resizeImage = async (imageData) => {

// Helper function to resize the image using a canvas
const resizeUsingCanvas = async (imageBitmap, newWidth, newHeight) => {
// Check if OffscreenCanvas is available
if (typeof OffscreenCanvas !== "undefined") {
const offscreenCanvas = new OffscreenCanvas(newWidth, newHeight);
const context = offscreenCanvas.getContext("2d");
context.drawImage(imageBitmap, 0, 0, newWidth, newHeight);
const offscreenCanvas = new OffscreenCanvas(newWidth, newHeight);
const context = offscreenCanvas.getContext("2d");
context.drawImage(imageBitmap, 0, 0, newWidth, newHeight);

// Get ImageData from the OffscreenCanvas
return context.getImageData(0, 0, newWidth, newHeight);
} else {
// Fallback to regular canvas (only necessary in rare cases)
const canvas = document.createElement("canvas");
canvas.width = newWidth;
canvas.height = newHeight;
const context = canvas.getContext("2d");
context.drawImage(imageBitmap, 0, 0, newWidth, newHeight);

return context.getImageData(0, 0, newWidth, newHeight);
}
// Get ImageData from the OffscreenCanvas
return context.getImageData(0, 0, newWidth, newHeight);
};

0 comments on commit 51da729

Please sign in to comment.