Dan Q
Hero Member ⚓︎
    
 

I have no idea what I am doing ⛺︎ My Room
RSS: 
Guild Memberships: Artifacts:
   
|
 |
« on: Autumn, 17 Nov 2026 @476 » |
|
Last week, I added some banners to MelonLand's Banner Club (and started hosting the banners on my site, of course!). Here's one, for example:Thing is... I'm not very good at graphic editing . I'm much stronger with HTML + CSS (with perhaps a little SVG and JavaScript). So I did what any sensible person would do...I made a program that can turn (almost) any Web "thing" into an animated GIF! Here was my thinking:- I'll make my banners in HTML, then
- I'll screenshot then a few hundred times over the course of a few seconds and combine those screenshots into a GIF (and then optimize it, of course, to get rid of unnecessary frames and generally make the file smaller!)
Step 1: making my bannerMaking a 400 × 40 banner in HTML + CSS is pretty easy. Just make a web page with something like this on it:<div id="sample-banner"
style="position: relative;
overflow: hidden;
width: 400px;
height: 40px;">
<!-- later, banner content will go here! -->
</div>
That's a 400 × 40 box. The position: relative; means that if I give everything inside it position: absolute;, I can position the things inside it relative to the banner. The overflow: hidden; ensures that anything that's "too big" for the banner gets clipped, rather that it being resized to fit the banner or the banner being resized to fit it.
Then I just started putting things inside it, using my browser's debug tools to tweak the CSS and move them around until I was happy. Like: the text on the right of my banner? Here's the code I used to create that:<div style="position: absolute; top: 1px; right: 21px; width: 50%; font-size: 14px; text-align: right; line-height: 18px; letter-spacing: 0.5px;">
working to make the
<br>
Internet fun and weird
</div>
Notice the position: absolute; that allows me to use top: and right: (I could also use e.g. bottom: or left:) to position the text anywhere I want relative to the banner's edges.
I added an SVG of me, waving (the waving animation is powered by CSS) that I use elsewhere on the site, but I could equally have used e.g. conventional images, or emoji, or even JavaScript to make an animated background or randomise things! Anything I can do on the Web, I can do in the banner!
Step 2: turning it into a GIF
The clever bit is turning that banner, made out of general purpose web technologies, into a GIF! Here's the program I wrote (you're welcome to take a copy for yourself if you want). Here's how to install it, if you want it:- Install NodeJS, if you haven't already. (NodeJS is a JavaScript interpreter than runs on the command-line, not in your browser. I'm using Node v24, but any version from v18 onwards will probably work.)
- Download my program into a directory by itself.
- In that directory, run npm init -y; npm pkg set type=module; npm install puppeteer pngjs gifenc to install everything my program depends upon; specifically it's installing Puppeteer, PNGJS, and GIFEnc. (Puppeteer lets my program remote-control a web browser to get the screenshots it needs; PNGJS or GIFEnc are used to save the resulting images.)
Now it's ready to run! My banner needs to be on a web page with a web address I know (it can be localhost!), and it needs an id="..." attribute, e.g. id="my-banner". Then I can run:node generate.js https://example.com/page#my-banner 3.5 70 output-file.gif
In that command:- https://example.com/page is the web address of the page my "banner" is on
- my-banner is its ID (note the # between it and the URL: just like if you were deep-linking to the banner!)
- 3.5 is the number of "seconds" to record for
- 70 is the number of "frames" to capture over that period, equally-spaced (70 frames over 3.5 seconds is 20 frames per second)
- output-file.gif is the file to create
It only takes a few seconds to run, so it's easy to tweak the parameters until you get something you like.
Step ∞?: turning almost any bit of your website into a GIF
Because all it's doing is rapidly-screenshotting web pages, it works with anything. Watch as I transform parts of some maybe-familiar websites into animated GIFs with a single command:node generate.js "https://forum.melonland.net/#bunting" 2.1 75 melonland-bunting.gif
node generate.js "https://melonking.net/melon#mainframe" 10 25 melonking-plot.gif
node generate.js "https://ascending.danq.dev/#scene" 4.3 25 ascending.gif
 Important: the GIFs this produces are big; run them through Ezgif Optimizer or something to make the files smaller before you publish them! 
Want more?
I've no idea if this is useful for anybody other than me. Personally, I love the fact that I can now design banners, 88×31s, blinkies, or whatever else using HTML and CSS (and optionally SVG, images, JS, etc.), and then convert them into GIFs. It also means I can make changes easily: if I want to change the colour of my shirt in the banner, that's one CSS variable; if I want to change the text, that's plain text in a HTML file... and I can just run the same command again to get a fresh GIF!
Let me know if it helps you! Or if you've got improvements to it (maybe I should embed LossyGIF/Gifsicle right into it so it makes better-sized GIFs to begin with? or maybe I should allow generic selectors, not just IDs?)!
I've taken a deeper-dive on my blog with some more hands-on examples of how I'm using it.
|