July 22, 2020

How to make simple serverless favicon generator

Today I got an idea for a quick side project: I wanted to build a simple favicon generator hosted on Cloudflare Workers.

I know, that it's definitely possible to generate images on AWS Lamba, however I haven't found any information if this is possible to do on CF Workers.

Initially I wanted to generate a favicon based on a letter or two from domain name, however I tried every single Node.js package which could be used to work with images - and sadly, non of them worked on Cloudflare Worker.

A few hours later I found a PNG-Pong - a dead-simple library to work with PNG images. Due to it's nature, the library itself is very limited - it provides a few methods to work with PNG files (like create a new image, and draw a rectangle).

As this library doesn't have any methods to work with text on images, I got an idea of making a favicons in pixel-art style. And then I thought that Github-like avatar placeholders could be a great fit to my side-project.

I've spent a few other hours to make this idea happen, and as a result I was able to generate PNG images in the following style:

fav

Pretty neat, right? The source code of the project is available on Github

© 2023 [maxico.dev] — All rights reserved.