astro-imagetools icon indicating copy to clipboard operation
astro-imagetools copied to clipboard

Weird blur/shadows on images

Open RobbieTheWagner opened this issue 2 years ago • 5 comments

I am getting some weird shadowy blurry things on my images and I am not sure why. Any ideas?

Screen Shot 2022-06-03 at 11 50 39 PM

This is my usage:

      <Img
        alt="A desktop and mobile app mockup being worked on by a tentacle."
        attributes={{
          img: {
            class:"h-auto max-w-xl mt-8 mx-auto w-full lg:ml-0 lg:mt-0"
          }
        }}
        format="webp"
        loading="lazy"
        src="/img/hero-images/app-development.png"
      />

RobbieTheWagner avatar Jun 04 '22 03:06 RobbieTheWagner

@rwwagner90 Is the image transparent?

RafidMuhymin avatar Jun 05 '22 17:06 RafidMuhymin

@rwwagner90 Is the image transparent?

@RafidMuhymin it's a png and has some transparency, yeah. Is there not png support?

RobbieTheWagner avatar Jun 05 '22 22:06 RobbieTheWagner

By default, astro-imagetools creates a blurred version of the original image (with a much smaller file size) and sets it as a background, with the idea that when the actual image loads in, it will cover up the blurred background. If there is transparency in the image, then the placeholder will show through.

As a workaround, you can set placholder="none" to avoid the blurred background.

According to Erika, astro-eleventy-img uses an onload to remove the background, perhaps that's something we could explore here too.

IanVS avatar Jun 06 '22 13:06 IanVS

@IanVS thanks for the tip, I am okay with no placeholders for my use case, I think. Will see how that goes. Definitely agree we should remove those background images. This is a pretty common case I think.

RobbieTheWagner avatar Jun 06 '22 14:06 RobbieTheWagner

Hey, quick fix example for the <Img /> component.

<Img {...props} attributes={{ img: { onload: "this.style.background = 'transparent';" } }} />

Of course it only works if the client has JS so I added this at the bottom of my <body>

<noscript><style is:inline>.astro-imagetools-img{background:none;}</style></noscript>

m4rrc0 avatar Jun 06 '22 23:06 m4rrc0