Keeping Pixely Images Pixely (and Performant!)
Keeping Pixely Images Pixely (and Performant!) êŽë š
After Marc chimed in with technique he needed to pull off as part of this years big promotion last week, it reminded me of another thing that ended up being relevant to the design aesthetic at play.
A horizontal slice of that background image was used here on this blog and the image size was quite tolerably small thanks to this CSS property.
See how everything has that 8-bit-ish pixely look to it? There is a CSS property that you can apply to images (<img>
elements) that will affect how they look when they scale. Like if youâve got an image like this:
Youâre probably going to want to do this no matter what:
.castle-landscape-image {
image-rendering: pixelated;
}
If there is any resizing at all any direction, itâs just going to look better. There is also image-rendering: crisp-edges;
which is apparently specifically for pixel art, but I donât see much of a difference.
Another cool thing we can do here is ensure the original art is as small as it can reasonably be (probably whatever size it was originally created at) and served like that, so any scaling beyond that doesnât cause any anti-aliasing stuff (blurred edges) at all. In the case of the example above where I didnât really have the original just a high-res version, I can scale it down and down trying to find the best place where it still looks fine but Iâm saving lots of image space:
Another use-case here is something like a QR code. This QR code is 393 bytes (super small!). Iâll render it huge here and see how perfect it looks:
I have an SVG version of this same QR code that is 33 KB. This is a (very rare) case where a simple vector-looking graphic is actually better served from a binary image that the natively vector SVG.
Even a bit more extreme, hereâs a 78 byte GIF (I hand-pixeled drew in Photoshop, and exported without metadata to get that small). It can scale up huge. Hereâs the tiny natural one on top and the big one below:
Note that if you try the crisp-edges
value on the above, it seems to bail out, so I guess there must be some kind of difference between the values.
Point of the story: if youâve got a pixely <img>
, chuck image-rendering: pixelated;
and go as small as you can to save on size.