Given an <img>
element, is it possible to pixelate the image using only CSS and/or not use canvas?
I've seen things like the crisp edges feature (but that's just for images that are scaled) and a lot of canvas options, but I'm hoping for a better way.
Is it possible to pixelate an image without canvas?
Asked Answered
You can achieve a pixelated affect by using the image-rendering: pixelated;
CSS rule and scaling up an image - see this article.
So if I want to keep the image at its natural size, what would you suggest? Scaling it, applying the
image-rendering
, and then clipping it to its original size? Or is there an easier way? –
Loyal That would work although you'd be clipping off part of the image (though it is pixelated). You could also try to save the source image in a smaller size than what you actually need it to appear in on your site, apply
image-rendering: pixelate;
, and scale it up to your desired size. –
Rhomb Yeah that's the problem, I won't have control over the images being displayed, so I can't just save it at a smaller size. –
Loyal
In that case, I would try to use
image-rendering
along with transform: scale(0.5);
and something like width: 200%; height: 200%;
. Some combination of those rules should be able to achieve what you're looking for. –
Rhomb Worth noting that this only works in webkit-based browsers as of 2019 –
Altostratus
© 2022 - 2024 — McMap. All rights reserved.
image-rendering: pixelated;
developer.mozilla.org/en/docs/Web/CSS/image-rendering – Signorino