import React, { useEffect, useState } from 'react'; interface ImageBlurryProps { src: string; alt?: string; classname?: string; key?: string | number; style?: React.CSSProperties; } const ImageBlurry: React.FC = (props) => { const { src, alt, classname, key, style } = props; const [imgSrc, setImgSrc] = useState(src); const [isError, setIsError] = useState(false); useEffect(() => { setImgSrc(src); }, [src]); const handleImage = () => { const pics = document.querySelectorAll('img'); pics.forEach((pic) => { if (pic.complete) { checkImage(pic); } else { pic.addEventListener('load', function () { checkImage(this); }); } }); }; const checkImage = (img: HTMLImageElement) => { if (img.naturalHeight > img.naturalWidth) { img.classList.add('portrait'); } else if (Math.abs(img.naturalHeight - img.naturalWidth) < 10) { img.classList.add('square'); } else { img.classList.add('landscape'); } }; const onLoad = () => { console.log('Image loaded:', src); handleImage(); }; return ( //
//
//
//
); }; export default ImageBlurry;