How to remove transparency from a TIF and replace with white 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
Roman80
Posts: 17
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

How to remove transparency from a TIF and replace with white background

Post by Roman80 » 2018-05-14T07:19:33-07:00

Hello,

i've attached an example file. How can I remove the transparency from a TIF file with ImageMagick C-API?
I already tried to debug with VisualMagick's tool "UTIL_convert" (VisualDynamicMT) with the command line parameter "[TIF_File] [JPG_File]" and this works, but I can't find out why.

Please could someone help?

Best Regards

https://www.dropbox.com/s/6b9khjnh74iauph/test.tif?dl=0

snibgo
Posts: 10134
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to remove transparency from a TIF and replace with white background

Post by snibgo » 2018-05-14T07:40:09-07:00

There are two APIs for C. Which one do you use?

What version of IM do you use?
snibgo's IM pages: im.snibgo.com

Roman80
Posts: 17
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

Re: How to remove transparency from a TIF and replace with white background

Post by Roman80 » 2018-05-15T00:12:27-07:00

Hello,
snibgo wrote:
2018-05-14T07:40:09-07:00
What version of IM do you use?
I use ImageMagick 7.0.7-22 Q16 x64 on Windows 10
snibgo wrote:
2018-05-14T07:40:09-07:00
There are two APIs for C. Which one do you use?
I don't know what you mean exactly, I use MagickCore and MagickWand. Hope this is what you expected.

Regards

snibgo
Posts: 10134
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to remove transparency from a TIF and replace with white background

Post by snibgo » 2018-05-15T02:57:37-07:00

The usual way of removing transparency is by flattening against a colour:

Code: Select all

magick in.png -background blue -layers flatten out.png
The MagickCore functions for this are:

Code: Select all

QueryColorCompliance ("blue", AllCompliance, &inImg->background_color, exception);

Image * outImg = MergeImageLayers(inImg, FlattenLayer, exception);
snibgo's IM pages: im.snibgo.com

Roman80
Posts: 17
Joined: 2017-08-03T21:26:15-07:00
Authentication code: 1151

Re: How to remove transparency from a TIF and replace with white background

Post by Roman80 » 2018-05-15T11:59:45-07:00

But in my case I have already a transparent background and want this to be replaced with a white background.

The following code do not work:

Code: Select all

QueryColorCompliance ("white", AllCompliance, &inImg->background_color, exception);
Image * outImg = MergeImageLayers(inImg, FlattenLayer, exception);
Regards

snibgo
Posts: 10134
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to remove transparency from a TIF and replace with white background

Post by snibgo » 2018-05-15T12:22:53-07:00

Roman80 wrote:The following code do not work:
It works fine for me. For you, does it compile? Does it run without error? How do you know it doesn't work?
snibgo's IM pages: im.snibgo.com

Post Reply