Case Study - Standardizing Image Aspect Ratios for Seamless Web Integration

I developed a CLI tool in Go to normalize client images to common aspect ratios, simplifying the integration process into my own web designs.

Date
Client
Opensource
Roles
Developer
Tech
Go,
Bash

The Challenge

When building out small websites for clients, they often send through images with inconsistent aspect ratios, meaning that I have to apply manual adjustments for use in my own web components/layouts.These manual adjustments are time-consuming, annoying, and costly to do for each client.

I wanted to build a tool that would automatically normalize a bunch of images to common aspect ratios. My goal was to make a CLI tool that took in specific image file path or a directory containing a images and then simply output the normalized images to a designated directory.

My Approach

I developed a CLI tool in Go that automatically adjusts images to the nearest common aspect ratio using a pretty naive algorithm (I should implement an interpolation method instead of picking the nearest pixel), but this has worked fine for my needs so far. The tool supports JPG, PNG, and WebP formats and preserves the directory structure during processing.

I've also added logging inside the output dir that specifies any errors encountered during image processing and provides a concise summary of what happened to each image. You can see the change in dimensions and the new aspect ratio as well as a message that indicates whether the image was processed or not and how it was handled.

The CLI tool allows you to specify a single file to normalize, or a root directory. If a directory is specified then the tool will recurse and process all images inside that directory, retaining the directory structure in its output.

I used a basic 'nearest-neighbor' image scaling algorithm for adjusting the image to a suitable aspect ratio but I've left it as scale down only.

The Outcome

The CLI tool has streamlined the image normalization process for me, drastically reducing manual effort. I use it frequently in instances where I just want to quickly confirm images are web-ready with consistent aspect ratios.

Limitations and Todos

The current version has limited tolerance customization and may need further optimizations for extremely irregular image sizes. Future updates aim to add more flexibility and support additional image formats but I'm kinda leaving it as is for now. I also need to make it installable so you don't need to clone to github repo and then build it yourself.

For the scaling algorithm I should implement an interpolation method (like bilinear) instead of picking the nearest pixel. This would result in a smoother resulting image, especially if scaling something up.

More case studies

Rebuilding the Classic Gymnastics website

I redid the Classic Gymnastics website in Next.js to improving website performance and adjust the styling to be more inline with modern standards.

Read More

Moving from Wix to Shopify | Rebuilding Resellerstore

I helped Reseller finish their website design that was originally done with Wix a while back. Now their business is expanding and they want to launch an e-commerce store, which I advised was best done on Shopify.

Read More

Revitalizing the Modern Coffee House Website

I designed and developed a website for a ROME, a boutique gym in Sydney. The site is fully responsive and has a clean, modern design and incorporates multiple integrations with the gym's mobile app and booking system.

Read More