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



Advertisement

One thought on “Adding a Background to Transparent PNGs in Bulk

  1. Pingback: Quick Resize with ImageMagick | Litot·es

Leave a Reply

Please log in using one of these methods to post your comment:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s