Converting Image Lost Background Color
Converting Image Lost Background Color
Hi Everybody,
Is there any command that give me the permission to maintain the background color when I convert an image
I've found a solution for convert only image with background or image without background but I need an univocal command that allow me to convert correctly image without knowing the background color
thank you all!!
p.s: I've tried to convert tiff to png (that usual keep transparency) but doesn't work
Is there any command that give me the permission to maintain the background color when I convert an image
I've found a solution for convert only image with background or image without background but I need an univocal command that allow me to convert correctly image without knowing the background color
thank you all!!
p.s: I've tried to convert tiff to png (that usual keep transparency) but doesn't work
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting Image Lost Background Color
What is your IM version and platform? Please post your exact command and the input tiff. What kinds of images are not maintaining the background color -- are they raster or vector formats? The latter is PDF, EPS, etc. The former are jpg, png, tiff, gif, etc. Is it only transparency that does not get maintained or some other colors?
Re: Converting Image Lost Background Color
I'm actually using ImageMagick-6.9.1-0-Q16-x64 for Win 10
from command line: convert img.tif img.png
I want to convert a Tiff into a PNG, if the Tiff have an opaque background no problem, but when i convert a Tiff with a transparent background authomatically the PNG appear with a white/black background
the images are bitmap, and yes it only transparency that doesn't get maintained
ps: I want only to know if it possible to have a univocal command that allow me to convert all the image that I have keeping the same background
from command line: convert img.tif img.png
I want to convert a Tiff into a PNG, if the Tiff have an opaque background no problem, but when i convert a Tiff with a transparent background authomatically the PNG appear with a white/black background
the images are bitmap, and yes it only transparency that doesn't get maintained
ps: I want only to know if it possible to have a univocal command that allow me to convert all the image that I have keeping the same background
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Converting Image Lost Background Color
Please show an example of a TIF file that loses transparency when converted to a PNG. You can upload to somewhere like dropbox.com, and paste the URL here.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting Image Lost Background Color
Tiff can have either background transparency or alpha channel transparency. That may be important to your problem. We need to see an example tiff image that fails, so we can see if there is a universal solution.
Re: Converting Image Lost Background Color
Actually I'm testing on an image that I've found in a post here, cause I need to convert a lot of imagessnibgo wrote:Please show an example of a TIF file that loses transparency when converted to a PNG. You can upload to somewhere like dropbox.com, and paste the URL here.
here is the link:
https://www.dropbox.com/s/lnravwtfvm6pl68/Hat.tif?dl=0
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Converting Image Lost Background Color
hat.tif contains two images. They both have clipping paths. The second has ordinary transparency, and a canvas offset.
Code: Select all
convert hat.tiff[1] +repage out.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting Image Lost Background Color
I believe this image is not properly formed. If I open it in PS, I see one layer with a clipping path. But when I get the verbose information from Imagemagick, it shows a clip path and 2 layers, but the first layer has two sets of color data.
If you convert the image in IM as
you will get two output png files. The first is the correct size, but has a white background. The second is transparent but bounded by the clip path, so it is smaller.
If you just want the transparent result, then
I thought to always take the last layer by using
but oddly IM objects with "no images defined"
But that does work with a valid image as
So that is another reason that I think your file is malformed. If not, then IM is misreading the clip path as a second layer and a developer would have to review your image to see what is going on.
Do you have other images that are like this one?
If you convert the image in IM as
Code: Select all
convert -quiet Hat.tif Hat.png
If you just want the transparent result, then
Code: Select all
convert -quiet Hat.tif[1] Hat.png
Code: Select all
convert -quiet Hat.tif[-1] Hat.png
But that does work with a valid image as
Code: Select all
convert rose:[-1] tmp.png
Do you have other images that are like this one?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting Image Lost Background Color
This will process the image correctly.
Code: Select all
convert -quiet Hat.tif \
\( -clone 0 -alpha on -channel rgba -evaluate set 0 \) \
\( -clone 1 \) \
-delete 0,1 -background none -flatten hat.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting Image Lost Background Color
I am not sure this is a malformed image. I have seen this problem before and what I wrote above was the solution. Tif files with background transparency seem to have a hidden layer for the actual image before placing it in the virtual canvas with the transparent background. I believe this problem was discussed before, but not sure if on or off the forum. You can try searching the forum if you want. I seem to recall discussing this with dlemstra some time ago. He may recall and can comment if he wants.
Re: Converting Image Lost Background Color
I've found
mogrify -format png -alpha deactivate -flatten -transparent white *.tif[0]
that works on images that have background color different from #ffffff
thanks all for the support
mogrify -format png -alpha deactivate -flatten -transparent white *.tif[0]
that works on images that have background color different from #ffffff
thanks all for the support