DEV Community

Cover image for ImgTool: When You Need to Process Images Without the GUI Drama
UltimateHobbyCoder
UltimateHobbyCoder

Posted on

ImgTool: When You Need to Process Images Without the GUI Drama

So here's the thing - I was tired of opening heavy image editing software or uploading images to online converters just to convert a bunch of PNGs to JPGs or resize images for web use. Then I thought that is a cool project to do: an lightweight image processing tool that does one thing really well and efficiently: coverting and resizing images.

What It Actually Does

ImgTool is a CLI tool written in Go that handles the most common image processing tasks you'll encounter:

  • Format conversion between PNG, JPG, GIF, and WebP
  • Quality adjustment for lossy formats (because nobody wants 10MB JPGs)
  • Image resizing with percentage scaling or specific dimensions
  • Watermarking with opacity control
  • Batch processing entire directories
  • Concurrent processing because why wait when you have multiple CPU cores?

Why Go?

I chose Go for a few reasons. First, it compiles to a single binary - no dependency hell, no "works on my machine" issues. Second, Go's concurrency model makes it perfect for processing multiple images simultaneously. And honestly, Go's standard library plus a few choice packages (cobra for CLI and viper for config) gave me everything I needed without bloat.

The Real-World Stuff

Let me show you how this actually works in practice:

Basic Format Conversion

.\imgtool.exe convert photo.png photo.jpg --to jpg --quality 85
Enter fullscreen mode Exit fullscreen mode

Resize for Web

.\imgtool.exe convert large-image.jpg thumbnail.jpg --resize "300x200"
Enter fullscreen mode Exit fullscreen mode

Bulk Processing

This is where it gets interesting. Need to convert an entire folder of images to WebP for better web performance?

.\imgtool.exe convert input-folder output-folder --mode dir --to webp --workers 8
Enter fullscreen mode Exit fullscreen mode

The --workers flag lets you control how many images get processed simultaneously. On my machine, 8 workers seems to hit the sweet spot between speed and not melting my CPU.

Adding Watermarks

.\imgtool.exe convert photo.jpg watermarked.jpg --watermark logo.png --watermark-opacity 70
Enter fullscreen mode Exit fullscreen mode

Configuration That Actually Makes Sense

Instead of remembering all those flags, you can create a config.yaml file:

to: "webp"
quality: 75
watermark: "/path/to/your/logo.png"
watermark-opacity: 60
workers: 8
Enter fullscreen mode Exit fullscreen mode

Now your common settings are defaults, and you only need to specify what's different for each job.

The Technical Bits

Under the hood, ImgTool uses Go's image package along with format-specific libraries. The concurrency is handled with goroutines and channels - nothing fancy, just effective. For directory processing, it walks the file tree, spawns worker goroutines, and processes images in parallel while maintaining a reasonable memory footprint.

The CLI is built with Cobra, which gives you all the nice help text and flag parsing without having to write boilerplate. Viper handles the configuration file parsing and merging with command-line flags.

Why I Built This

Look, there are plenty of image processing tools out there. ImageMagick is powerful but can be overwhelming. Online converters work but who wants to upload files for simple tasks? GUI tools are great but slow for batch operations.

I wanted something that:

  • Starts instantly (no splash screens)
  • Handles the 80% use case really well
  • Doesn't require learning a complex syntax
  • Can process hundreds of images without breaking a sweat

What's Next

The tool is available for Windows right now, and I'm working on making it easily installable for Linux and macOS (if you're on those platforms, you can still build from source with a bit configuration(maybe?!).). I'm also considering adding more filters and effects, but only if they serve real-world use cases.

The code is open source on GitHub, and I've got documentation at prathamghaywat.github.io/imgtool-docs/.

Try It Out

If you're dealing with image processing tasks regularly, give ImgTool a shot. It's designed to be the tool you reach for when you need something done quickly and correctly, without the overhead of larger applications.

And hey, if you find bugs or have ideas for improvements, the issues tab on GitHub is always open. Building tools that people actually use is the best kind of feedback loop.


*ImgTool is MIT licensed and available on GitHub. *

Top comments (0)