Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go

Transparent Images


2018-05-06 A common requirement when working with graphics files that you want to include in a colourful document or to place on your web page is to convert its background from white to being transparent. Both GIF and PNG images support transparency but JPG does not. With a transparent background an image will often blend nicely with the web page or presentation background colour.

We can replace the white background of a JPG image with a transparent background to create a PNG image using convert from imagemagick. The key option is -transparent:



  $ convert -transparent white orig.jpg trans.png
  $ display trans.png

After conversion we will want to display to image to ensure all is as expected.

If the white in the original is not pure, as is often the case, we can introduce some fuzziness to improve the capture more of the background of the image as transparent using -fuzz:



  $ convert -transparent white -fuzz 15% orig.jpg trans.png
  $ display trans.png


Copyright © 1995-2018 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware and the author of the open source software Rattle and wajig.
Also the author of Data Mining with Rattle and Essentials of Data Science.