Mary Knize

Glitch Art with SoX, ImageMagick, and Vim

3 min read


Databending is a method for creating glitchy images by altering raw image data using a variety of techniques. I wanted to experiment with this, so I've found a few ways to glitch out some photos on the Linux command line with SoX, ImageMagick, and Vim.

First, I found a photo on Pexels that I wanted to glitch out. Then, I got SoX with sudo apt-get install sox. I already had ImageMagick and Vim installed.

Before getting started with SoX, I converted the image from jpg to bmp with ImageMagick. Uncompressed images work best when using audio editors to mess with images.

mogrify toycar1.jpg toycar1.bmp


Now I'm ready to start editing with SoX. I'm going to run the image through the echo and phaser filters.

  • -t ul sets the filetype to a raw format.
  • -c 1 sets the channel to 1.
  • -r 48k sets the sample rate.
  • trim 0 100s skips the first 100 samples. This is so it doesn't destroy the image headers.
sox -t ul -c 1 -r 48k toycar1.bmp -t ul toycar2.bmp trim 0 100s : echo 0.4 0.8 10 0.9


sox -t ul -c 1 -r 48k toycar2.bmp -t ul toycar3.bmp trim 0 100s : phaser 0.3 0.9 1 0.7 0.5 -t


After running those two filters, I decided to run the image through an ImageMagick filter. Since I already had it installed, it was easy to add a paint filter.

convert toycar3.bmp -paint 5 toycar4.bmp


Then, I went back to SoX and ran a flanger filter without any arguments.

sox -t ul -c 1 -r 48k toycar4.bmp -t ul toycar5.bmp trim 0 100s : flanger


Then back to ImageMagick to posterize the colors.

convert toycar5.bmp -posterize 3 toycar6.bmp


Finally, I decided to use Vim to manually mess with some of the data. Before doing so, I converted the bmp back to jpg. With the compressed image file it's much easier to delete and duplicate random lines to create super glitchy and destructive effects.

convert toycar6.bmp toycar7.jpg

image vim

I like to delete or duplicate a line, save, and then refresh the image in the image preview to see what happened. If I don't like an effect I can always undo and try something else. On this image I started at about line 13 to make sure I didn't destroy the image headers. If you start from the first line of the image you will corrupt the image.

After a bit of destructive editing, I got a result that I liked. It kind of looks like a low-res image of a bus speeding across the surface of Mars.


Canonical URL