container. */
+ className?: string,
+ /** URL to the image */
+ src: string,
+ /** Extra CSS styles on the outer
element. */
+ style?: React.CSSProperties,
+}
+
+/** Renders images on a canvas, only playing GIFs if autoPlayGif is enabled. */
+const StillImage: React.FC
= ({ alt, className, src, style }) => {
+ const settings = useSettings();
+ const autoPlayGif = settings.get('autoPlayGif');
+
+ const canvas = useRef(null);
+ const img = useRef(null);
+
+ const hoverToPlay = (
+ src && !autoPlayGif && (src.endsWith('.gif') || src.startsWith('blob:'))
+ );
+
+ const handleImageLoad = () => {
+ if (hoverToPlay && canvas.current && img.current) {
+ canvas.current.width = img.current.naturalWidth;
+ canvas.current.height = img.current.naturalHeight;
+ canvas.current.getContext('2d')?.drawImage(img.current, 0, 0);
+ }
+ };
+
+
+ return (
+
+

+ {hoverToPlay &&
}
+
+ );
+};
+
+export default StillImage;
diff --git a/app/soapbox/components/ui/avatar/avatar.tsx b/app/soapbox/components/ui/avatar/avatar.tsx
index 6818509e8..1b02c6d25 100644
--- a/app/soapbox/components/ui/avatar/avatar.tsx
+++ b/app/soapbox/components/ui/avatar/avatar.tsx
@@ -25,7 +25,7 @@ const Avatar = (props: IAvatar) => {
return (