How to set background color in ImageMagick

PDF, SVG, PNG and many other image formats can have a transparent background. Sometimes, you might want to set the background color in image files. This can be done easily using the -background and -flatten options.

For example, to convert a PDF to JPG file and set the background color in the resulting file to white:

$ convert foo.pdf -background "#FFFFFF" -flatten foo.jpg

Tried with: ImageMagick and Ubuntu 14.04


2 thoughts on “How to set background color in ImageMagick”

  1. ImageMagick is sakkath useful kano. Recently I visited NY and had to walk a lot. I didn’t want to waste battery & spend my limited download limit in loading directions in my phone GPS. So I looked it up online and saved it and converted it to png files and copied it to my phone.


    1. Piri: Yes, ImageMagick turns out to be a great way to automate image operations. BTW for maps, try the Maps.Me Android app. You can download OpenStreetMap maps for every country/state/city in it and use offline.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s