Adding a Background to Transparent PNGs in Bulk

So I had a bunch of PNGs with transparent backgrounds that needed instead to be white. This is the kind of thing that ImageMagick is so good for, but this turned out to be a little bit harder.

I couldn’t find a way to add a background (or any kind of layer at all) to an existing image, but you can add one image to another.

  1. Make an all white graphic the same size as the PNGs (I don’t know what you’d do if you had images of different sizes). It seems like this is the step that you should be able to do on the fly.
  2. (Enter all on one line) for i in *.png; do composite -compose Over $i background.png ${i:r}-on-white.png; done