Making image transformations fun

A month or two ago, I noticed a post on Hacker News (or was it reddit?) about pixQL, which provides an sql-like syntax to query and create images. I was intrigued, and thought it was a really cool idea. A simple scripting language that made it easy to do programmatic transformations on images.

I decided I wanted to create my own take on this idea. It wasn’t that I thought I could do better than pixQL, or that I thought anything was missing from pixQL. I just really like designing languages and then implementing them from scratch. I picked C# to implement my new language, with plans to move it to C++ after getting the idea fleshed out. I named the project ImageQuery.

The initial version of ImageQuery is written in C# and made up of two main components: The ImageQuery library, which provides an API to access the language, and IMQ, which acts as a command-line frontend.

Image Query Language

I named the language that ImageQuery uses IQL, or the Image Query Language. Here’s a quick sample of what it looks like:

input in
output out[in.width, in.height]

param num spacing = 5
param num size = 3
param color gridColor = {0}

out: select color from in where x % spacing < size and y % spacing < size else gridColor

Those 8 lines of code (1 if you ignore the boilerplate input/output definitions and don’t allow specifying parameters) create a grid pattern on top of the input image. For example, here we have an input:



Now let’s add a blue grid:

IMQ.exe -i in infinity.jpg -o out out.png -d gridColor "{0,0,1}" grid.iql

The output:

grid output sample


The command is fairly simple: It defines the input and output, some parameters, and the IQL file to run. IMQ also has the option to run as an interactive shell, which can be turned on with the -c or -interactive options.

Fun Stuff

I’m going to end here, but not before dropping a quick IQL script for you to try. See if you can guess what it does before running it!

Source Code (Github)

input in
output out[in.height,in.width]

out[y,x]: select {(r + g + b)/3} from in

Leave a Reply