Skip to content

Commit

Permalink
less render
Browse files Browse the repository at this point in the history
  • Loading branch information
beggers committed Nov 21, 2024
1 parent 2b2eca5 commit 99f6862
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/components/EffectsSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { FabricImage, ImageProps } from 'fabric';
import { FabricImage } from 'fabric';

interface EffectsSidebarProps {
overlayImages: FabricImage[];
Expand Down
36 changes: 18 additions & 18 deletions src/components/ImageCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ function ImageCanvas({ image, overlayImages, setDownloadableImage }: ImageCanvas
const canvasRef = useRef<HTMLCanvasElement | null>(null);
const fabricCanvasRef = useRef<Canvas | null>(null);

function updateDownloadableImage() {
if (!fabricCanvasRef.current) return;
useEffect(() => {
function updateDownloadableImage() {
if (!fabricCanvasRef.current) return;

// TODO other image types
const downloadableImageUrl = fabricCanvasRef.current.toDataURL({
format: 'png',
multiplier: 1
});
const base64Data = downloadableImageUrl.replace(/^data:image\/png;base64,/, '');
// TODO other image types
const downloadableImageUrl = fabricCanvasRef.current.toDataURL({
format: 'png',
multiplier: 1
});
const base64Data = downloadableImageUrl.replace(/^data:image\/png;base64,/, '');

const byteCharacters = atob(base64Data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
const byteCharacters = atob(base64Data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], { type: 'image/png' });
setDownloadableImage(blob);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], { type: 'image/png' });
setDownloadableImage(blob);
}

useEffect(() => {
if (!fabricCanvasRef.current && canvasRef.current) {
const canvasElement = canvasRef.current;
const parentElement = canvasElement.parentElement;
Expand Down Expand Up @@ -82,7 +82,7 @@ function ImageCanvas({ image, overlayImages, setDownloadableImage }: ImageCanvas
reader.readAsDataURL(image);

}
}, [image, overlayImages]);
}, [image, overlayImages, setDownloadableImage]);

return (
<div className="image-preview">
Expand Down

0 comments on commit 99f6862

Please sign in to comment.