Load images with cors allowed

Without allowing cors it is e.g. not possible to extract colors from an image
This commit is contained in:
schroda
2025-01-26 03:51:43 +01:00
parent 2579ba92a3
commit 25e3fc7808
4 changed files with 30 additions and 10 deletions

View File

@@ -35,6 +35,7 @@ interface IProps {
shouldDecode?: boolean;
useFetchApi?: boolean;
allowCors?: boolean;
priority?: Priority;
@@ -46,6 +47,7 @@ export const SpinnerImage = forwardRef((props: IProps, imgRef: ForwardedRef<HTML
shouldLoad = true,
shouldDecode,
useFetchApi,
allowCors,
src,
alt,
onLoad,
@@ -84,7 +86,7 @@ export const SpinnerImage = forwardRef((props: IProps, imgRef: ForwardedRef<HTML
return () => {};
}
const imageRequest = requestManager.requestImage(src, { priority, shouldDecode, useFetchApi });
const imageRequest = requestManager.requestImage(src, { priority, shouldDecode, useFetchApi, allowCors });
let cacheTimeout: NodeJS.Timeout;
const fetchImage = async () => {
@@ -156,6 +158,7 @@ export const SpinnerImage = forwardRef((props: IProps, imgRef: ForwardedRef<HTML
}),
]}
ref={imgRef}
crossOrigin={allowCors ? 'anonymous' : undefined}
src={imageSourceUrl}
alt={alt}
draggable={false}