Two weeks ago I made a page to keep track of current and future projects. Today, that page finally paid off! I've executed one of the project ideas present in there, the WebP Converter! Made in Python!

You select an input directory, and it'll identify all the JPG and PNG files.

You then press the convert button and select an output directory, and the conversion will start. I've made it display how much the file size was reduced so I know this thing is actually worth it. I was thinking of trying out something like the TinyPNG API or some premade algorithm to compress the files before converting to WebP, but I don't think I really need to since these results are pretty good! Here's the results for all of the images that make up this post!

It doesn't always reduce the file size though. For some smaller files it can increase it by quite a lot. Some larger files that are really optimized also get an increase. But for my use case — images for my Neocities — it serves quite well!

I want to maybe tinker with the UI a little more but overall I'm pretty happy with the result! The conversion code itself is extremely simple actually. Pillow handles all of it in just two lines.

There was some work to locate the files but it's nothing complicated. This whole thing is only 220 lines of code and most of them are used to assemble the UI because Tkinter is atrocious. I'm actually using CustomTkinter which makes things slightly easier, but it's still a slog.
I did have to do some minimal puzzle solving though. The conversion code takes a reasonable amount of time as image manipulation does, and since Tkinter updates everything on the main thread it made the progress bar not progress as it should. The solution was kinda simple too, I just had the images be converted on a new thread each and have them call back on finish to avoid having to block the main thread waiting for all of them to join. This is like nothing to a "Real Programmer", but it was pretty fun to actually get to use one of the things I learned in college! Hurray for higher education!
I kinda want to put this on Github even if it's nothing too impressive, just to have it backed up somewhere. Though I don't want to put it on my main Github account because my deadname and my university are very visible on there. I'm thinking of making a new Github account for these little projects maybe, but then whenever I do come out/get a name change I'll have two unrelated accounts. And that'd also mean making another account, writing the password down, the mental toll that comes with having yet another account. Ugh. A problem for future Mei.