A Weekend Fixing Twelve Years of Bad Image Habits With Claude Code

A Weekend Fixing Twelve Years of Bad Image Habits With Claude Code

Tutorials ai-tools automation blogging claude code image optimization

I finally sat down this week and did the thing I'd been putting off since May: actually using Claude Code for something other than poking at it in a terminal window out of curiosity. Anthropic pushed it out more widely alongside the Claude 4 models a few weeks back, and I'd installed it, run claude once, asked it to explain a regex, and then closed the laptop like a coward. This weekend I gave it an actual job: cleaning up the image pipeline on this very blog.

Here's the backstory, because it's dumb and very on-brand for me. Techpad has been running since November 2011, and for most of that time I've been hand-resizing images in an ancient copy of an image editor before uploading them, because at some point in 2013 I got burned by a plugin that auto-compressed everything into mush and I never trusted automation again. Twelve years later I've got a media folder with 3,400-odd files in wildly inconsistent sizes, no alt text on maybe two-thirds of them, and a handful of images that are still, embarrassingly, uncompressed PNGs north of 4MB sitting on posts from 2015.

So I asked Claude Code to write me a script. Not "fix my blog," which is the kind of vague request that gets you nothing useful, but something specific: walk the images directory, find anything over 500KB, convert it to WebP at 80% quality, keep the original in a backup folder, and log what it did to a CSV so I could sanity-check the output before touching anything live. It wrote the script in about a minute, in Python, using Pillow, and asked me two clarifying questions about whether I wanted to preserve EXIF data (I didn't) before it ran. That back-and-forth is the part that actually sold me on it: it's not just generating code and hoping, it's asking the dumb-but-necessary question first.

It ran through all 3,400 files in under four minutes on my old ThinkPad. I lost about 1.2GB off the media directory. A few images from a 2012 post about, of all things, a Nokia Lumia review came out looking slightly worse than I'd like, so I kept those as PNGs and moved on with my life. Not everything needs to be perfect.

The part that actually took effort

The image compression was the easy 80%. The alt text was the annoying 20%, because it required me sitting there feeding it images and old post context one at a time so it could write something that wasn't generic garbage like "image of a phone." I ended up writing a small loop that pulled the surrounding paragraph text for context before generating each description, which helped a lot — an alt tag that says "the Lumia 900's AMOLED screen next to an iPhone 4S for comparison" is a completely different thing from "phone comparison photo," and only one of those is worth anything to a screen reader or to Google.

If you want to try something like this yourself, the setup is genuinely not complicated:

  1. Install the CLI, point it at your project directory
  2. Describe the task narrowly: file types, size thresholds, what "done" looks like
  3. Let it ask you questions before it writes anything destructive
  4. Always, always run it against a copy first. I did not always do this and I do not recommend skipping it.

One complaint, because no post here is complete without one: the thing is genuinely great at scoped, well-defined tasks and noticeably worse the second you get vague with it, and I watched myself waste twenty minutes arguing with a prompt that should've just been three separate, boring instructions. That's on me, not the tool, but it's the kind of lesson I seem to have to relearn every time a new one of these comes out.

Total time from "I should really deal with this" to actually deployed: about three hours, most of which was me manually checking output rather than anything the tool was slow at. Compare that to the fact that I've been meaning to fix this specific problem since roughly 2019. Make of that what you will.

If anyone wants the actual script I'll drop it in a gist and link it here — it's nothing fancy, maybe sixty lines, but it saved me a weekend I would've otherwise spent doing this by hand in an editor from a decade ago.