Tweaking PNG transparency with ImageMagick

This took me way too long to find out, so I thought I’d blog here and hopefully save someone else some time.

ImageMagick is a great swiss-army-knife type tool, with a shed-load of options for converting and combining images. Unfortunately, the sheer number of options can make it a bit time-consuming and frustrating trying to find the one you want.

My aim was simple: given a PNG, make the whole thing semi-transparent.

Searching Google using “transparent” and “opacity” drew a blank – all I got was instructions on how to set transparency for certain colours – not what I wanted to do.

The word I was missing was “alpha”, and the magic incantation for changing the opacity of the whole image is:


convert input.png -channel Alpha -evaluate Divide 2 output.png

In my case, I wanted to set the PNG to be 50% transparent (hence “Divide 2″.) Of course, you can change that number to whatever works for you.

Posted Tuesday, July 22nd, 2008 under Tip.

11 comments

  1. thanks, man :) you saved my day

  2. Thanks man yr one blog post solved my problem. Thank you for sharing

  3. helped me! thanks.

  4. Thank you!

  5. A quick fix for my problem as well. ;) Big thx.

  6. Thanks, that was really helpful.

  7. Big thx for the tip ;-)

  8. That’s cool! I wonder how much time I would have spent :)

  9. Thanks so much for having this on the web. I was going crazy trying to do a simple opacity change and was stuck in ImageMagicK syntax hell.

  10. Thanks heaps for posting this. Lifesaver!!!

  11. Another “thanks a lot” up here.

    Also, you can say the same with “convert input.png -channel Alpha -evaluate Set 50% output.png”.