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
Thanks!
keep transparent background
Re: keep transparent background
what format are you converting to ?When I convert ai, eps, pdf, psd or png files
How are you doing it Windows, linux, php etc?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: keep transparent background
Try setting -background none before reading.
NOTE some vector images actually 'draw' the background as well. Caution needed.
NOTE some vector images actually 'draw' the background as well. Caution needed.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: keep transparent background
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.
$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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: keep transparent background
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.
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/
https://imagemagick.org/Usage/