Tags: mag

3015

sparkline

Wednesday, May 18th, 2022

Banjo, whistle, box and fiddle players gathered around a pub table, all playing together.

Playing tunes.

Sunday, May 15th, 2022

Image previews with the FileReader API

I added a “notes” section to this website eight years ago. I set it up so that notes could be syndicated to Twitter. Ever since then, that’s the only way I post to Twitter.

A few months later I added photos to my notes. Again, this would get syndicated to Twitter.

Something’s bothered me for a long time though. I initially thought that if I posted a photo, then the accompanying text would serve as a decription of the image. It could effectively act as the alt text for the image, I thought. But in practice it didn’t work out that way. The text was often a commentary on the image, which isn’t the same as a description of the contents.

I needed a way to store alt text for images. To make it more complicated, it was possible for one note to have multiple images. So even though a note was one line in my database, I somehow needed a separate string of text with the description of each image in a single note.

I eventually settled on using the file system instead of the database. The images themselves are stored in separate folders, so I figured I could have an accompanying alt.txt file in each folder.

Take this note from yesterday as an example. Different sizes of the image are stored in the folder /images/uploaded/19077. Here’s a small version of the image and here’s the original. In that same folder is the alt text.

This means I’m reading a file every time I need the alt text instead of reading from a database, which probably isn’t the most performant way of doing it, but it seems to be working okay.

Here’s another example:

In order to add the alt text to the image, I needed to update my posting interface. By default it’s a little textarea, followed by a file upload input, followed by a toggle (a checkbox under the hood) to choose whether or not to syndicate the note to Twitter.

The interface now updates automatically as soon as I use that input type="file" to choose any images for the note. Using the FileReader API, I show a preview of the selected images right after the file input.

Here’s the code if you ever need to do something similar. I’ve abstracted it somewhat in that gist—you should be able to drop it into any page that includes input type="file" accept="image/*" and it will automatically generate the previews.

I was pleasantly surprised at how easy this was. The FileReader API worked just as expected without any gotchas. I think I always assumed that this would be quite complex to do because once upon a time, it was quite complex (or impossible) to do. But now it’s wonderfully straightforward. Story of the web.

My own version of the script does a little bit more; it also generates another little textarea right after each image preview, which is where I write the accompanying alt text.

I’ve also updated my server-side script that handles the syndication to Twitter. I’m using the /media/metadata/create method to provide the alt text. But for some reason it’s not working. I can’t figure out why. I’ll keep working on it.

In the meantime, if you’re looking at an image I’ve posted on Twitter and you’re judging me for its lack of alt text, my apologies. But each tweet of mine includes a link back to the original note on this site and you will most definitely find the alt text for the image there.

Saturday, May 14th, 2022

Checked in at Vine Street Tap. Daydrinking — with Jessica map

Checked in at Vine Street Tap. Daydrinking — with Jessica

People sitting around in the dappled sunshine on the green grass in a park with the distinctive Indian-inspired architecture of the Brighton Pavilion in the background, all under a clear blue sky.

Brighton in the sun.

Friday, May 13th, 2022

A close-up of a microphone in a practice room. In the background, a guitar player tunes up and a bass player waits to start.

Time to go play some songs with @SalterCane.

Thursday, May 12th, 2022

Fuzzy blobs of orange light in the shape of ring.

Watching the livestream of @KLBouman introducing us to @EHTelescope’s image of Sagittarius A*—amazing!

Wednesday, May 11th, 2022

A fiddler, a flute player, and a button accordion player playing around a table with pints of beer on it.

Playing tunes.

Friday, May 6th, 2022

Checked in at Baker Street Coffee. Flat whites — with Jessica map

Checked in at Baker Street Coffee. Flat whites — with Jessica

> I wanna build a spaceship, go to the Moon, salvage all the junk that’s up there, bring it back and sell it. https://twitter.com/reel_geek/status/1521580826537910275

I wanna build a spaceship, go to the Moon, salvage all the junk that’s up there, bring it back and sell it.

https://twitter.com/reel_geek/status/1521580826537910275

Thursday, April 28th, 2022

How to Imagine Climate Futures - Long Now

The best climate fiction can do more than spur us to action to save the world we have — it can help us conceptualize the worlds, both beautiful and dire, that may lie ahead. These stories can be maps to the future, tools for understanding the complex systems that intertwine with the changing climates to come.

Replying to

I’ve used this as an example in conference talks about interaction design.

I’ve used this as an example in conference talks about interaction design.

Wednesday, April 27th, 2022

Checked in at Jolly Brewer. Wednesday night session ☘️🎶🎻 — with Jessica map

Checked in at Jolly Brewer. Wednesday night session ☘️🎶🎻 — with Jessica

Wednesday, April 20th, 2022

Checked in at Jolly Brewer. Session ☘️🎶 — with Jessica map

Checked in at Jolly Brewer. Session ☘️🎶 — with Jessica

Monday, April 18th, 2022

Hanging out in the sun with not-my-cat. ☀️🐈

Hanging out in the sun with not-my-cat. ☀️🐈

Saturday, April 16th, 2022

Checked in at Stanmer Woods. Walking in the woods — with Jessica map

Checked in at Stanmer Woods. Walking in the woods — with Jessica

Wednesday, April 13th, 2022

Checked in at Jolly Brewer. Wednesday night session — with Jessica map

Checked in at Jolly Brewer. Wednesday night session — with Jessica

Tuesday, April 12th, 2022

Picture perfect images with the modern img element - Stack Overflow Blog

Addy takes a deep dive into making sure your images are performant. There’s a lot to cover here—that’s why I ended up splitting it in two for the responsive design course: one module on responsive images and one on the picture element.

Saturday, April 9th, 2022

Checked in at Coffee@33. Flat white — with Jessica map

Checked in at Coffee@33. Flat white — with Jessica

Checked in at The Edge Community Centre. Learning a new tune — with Jessica map

Checked in at The Edge Community Centre. Learning a new tune — with Jessica

Wednesday, April 6th, 2022

Checked in at Jolly Brewer. Tunes! — with Jessica map

Checked in at Jolly Brewer. Tunes! — with Jessica