OKAY you guys nerd sniped the hell out of me.
This is pretty unimpressive as web servers go (it's two separate barebones pages), but I do have a proof of concept here:
https://alttext.fly.dev/index.html
If you use most browsers, it will render totally normally, but if your browser sends a user-agent that starts with the string "lynx" or "elinks", it will filter the page you requested for "img" tags, run those images through an ascii-art image-to-text thingy, and replace the IMG tag with a PRE tag containing the ascii-art output (and then serve you THAT).
Were I to expand this into something like an actual image-hosting site, it'd probably do the asciiartification on upload. But then you'd still only get the effect if you were viewing it on this server; cross-links would just serve the file normally. (You can't actually serve "text/plain" to a browser expecting some sort of image content and have it work, which is why this implementation has to process the text of the HTML file before sending it.)
Anyway, it's possible, in a limited way!
. #NerdSnipe . #AsciiArt
Thanks!
Now I just have to figure out how to make this useful.
Like, if you could respond to an image request with content-type: text/html and have the browser insert an arbitrary tag into the DOM, I'd be golden. I mean, this can happen if a page is using something like HTMX, but obviously if you're an image hosting site, the idea is that you're just serving images to go ANYWHERE, and so can't guarantee anything about the target page. Also if you're targeting lynx, a client-side JS "solution" certainly isn't one.
🫤🙎🏻