keep transparent background

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mindstorm

keep transparent background

Post by mindstorm »

When I convert ai, eps, pdf, psd or png files, they are created with a white background, instead of maintaining their original transparent background. How can I make them maintain their original transparency? I have tried '-alpha On' with no luck. I can't use color removal because the images being uploaded will come in all colors and I would risk removing some of that data.

Please Help :D
Thanks!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: keep transparent background

Post by Bonzo »

When I convert ai, eps, pdf, psd or png files
what format are you converting to ?

How are you doing it Windows, linux, php etc?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: keep transparent background

Post by anthony »

Try setting -background none before reading.

NOTE some vector images actually 'draw' the background as well. Caution needed.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
mindstorm

Re: keep transparent background

Post by mindstorm »

Thanks Anthony. I'm converting to png on an apache server. Could the order of operation be an issue? I'm flattening for psds. Does that need to be done before setting background none?


$thumb = '/thumb_'.$file_basename.'.png';
$cmd = '/usr/local/bin/convert '.$img.' -resize 200 -flatten -background none '.$thumb;

I have also notice that using -transparent white doesn't always work with vectors, as you mentioned with drawing the background. Is this due to a saving preference?

Update:
Moving -flatten after setting background fixed the issue with most files.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: keep transparent background

Post by anthony »

The -background none was for vector images as should have been set BEFORE reading such an image. In most cases this will have the image draw on a transparent background rather than the 'white' default.

Remember reading an image is actually itself just a 'operation' in IM, one that does not need some type of -read type operator.

If done before outputing, as you specified, it will only effect image file formats that have a 'background setting, such as GIF's, though few programs (other than IM) will make use of such a setting that was saved with the image file format, it is typically ignored!

ASIDE....

IM only uses it if -background has NEVER been set or is turned off (using +background ) before reading the image. In other words only in special and uncommon situations.

This by the way does cause some confusion in those rare situations as basically IM does not really have an idea of a 'global' setting for background, as a separate entity to individual images 'background meta-data' setting, even though it seems like it does.

I am wanting to see the idea of a proper 'global' setting as separate to individual image meta-data, added, but this my require a major version change.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply