combining two images

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
cs_rol
Posts: 22
Joined: 2007-01-16T04:40:08-07:00

combining two images

Post by cs_rol »

Hello!

I've got two images one is a TIFF and the other is an PNG and they have same dimensions.
Only the PNG image has transparency information.
Does anyone know how to apply the transparency information to tiff, preserving other settings (colorspace and so on)
I tried with combine and the transparency chanel but I didn't find any solution.
thanks in advance!

The two pics:
http://www.werk3at.net/rol/Winter2.tif
http://www.werk3at.net/rol/Winter2.png


greets richard
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: combining two images

Post by Bonzo »

Hello Richard

I have just had a go at your problem but my server does not seem to understand tif !

Anyway on downloading untitled.png my PC kept renaming it to a .bmp could there be a problem with this file ?
I change the black on the untitled file to transparent and saved it as a png then tried a couple of things and I have the transparency on the png but no sign of the tif.
I then tried using a jpg for the background image then added the png file and it seemed to work Ok.

I would try a different png and see what happens.
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: combining two images

Post by RetroJ »

I think a bug has been uncovered here. In the course of figuring out the command to do what you describe, I found this:

This produces a transparent image, as expected:

Code: Select all

convert Winter2.png -fill none -draw "color 0,0 reset" test.png
But if we use Winter2.tif as the source image, the output is not transparent.

Code: Select all

convert Winter2.tif -fill none -draw "color 0,0 reset" test.png
Therefore this fails:

Code: Select all

convert Winter2.tif -fill none -draw "color 0,0 reset" Winter2.tif \( Winter2.png -channel matte -negate -separate \) -composite test.png
But this works:

Code: Select all

convert Winter2.png -fill none -draw "color 0,0 reset" Winter2.tif \( Winter2.png -channel matte -negate -separate \) -composite test.png
ImageMagick 6.3.2 01/20/07 Q16 in Debian.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: combining two images

Post by anthony »

After reading in the TIF try adding the -matte operator. This ensures the image has a matte/transparency or alpha channel added, before you attempt to add transparent color to the image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: combining two images

Post by RetroJ »

Thanks, Anthony.

This works:

Code: Select all

convert Winter2.tif -matte -fill none -draw "color 0,0 reset" Winter2.tif \( Winter2.png -channel matte -negate -separate \) -composite test.png
cs_rol
Posts: 22
Joined: 2007-01-16T04:40:08-07:00

Re: combining two images

Post by cs_rol »

Thank you for for the replies. The commands mentioned work perfectly for PNG-results. but i ned the TIFF, because only the TIFF-images has right colorspace information and so on (PNG only supports RGB).
If i just change the extension to .tiff the background is black and there's no transparency.

greets richard
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: combining two images

Post by RetroJ »

cs_rol wrote: Thank you for for the replies. The commands mentioned work perfectly for PNG-results. but i ned the TIFF, because only the TIFF-images has right colorspace information and so on (PNG only supports RGB).
If i just change the extension to .tiff the background is black and there's no transparency.

This works for me:

Code: Select all

convert Winter2.tif -matte -fill none -draw "color 0,0 reset" Winter2.tif \( Winter2.png -channel matte -negate -separate \) -composite test.tiff
I'm using ImageMagick 6.3.2-5 Q16.
cs_rol
Posts: 22
Joined: 2007-01-16T04:40:08-07:00

Re: combining two images

Post by cs_rol »

i resolved this by changing the tiff-coder by adding an asociated alpha channel in order to make the file be displayed correct in photoshop

tiff.c@~line1734

Code: Select all

sample_info[0]=EXTRASAMPLE_ASSOCALPHA;// remove: EXTRASAMPLE_UNASSALPHA
Now I have the task to implement this command with MagickWand or MagickCore. Can anyone tell me the lines of code to implement this features? I tried several times but i didn't come to an appropriate result.

thanks in advance and greez
richard
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: combining two images

Post by el_supremo »

If I understand your request correctly, you want to copy the alpha channel from the png to the tif, in which case this command should do it:

Code: Select all

convert Winter2.tif -matte Winter2.png -compose Dst_In -composite winter2_out.png
I can't test it with a TIF as output but it does work when output to a PNG.
If that's what you need then this C function does the same thing:

Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(void)
{
	MagickWand *m_wand = NULL;
	MagickWand *a_wand = NULL;


	MagickWandGenesis();
	
	/* Read the TIF and add an alpha layer */
	m_wand = NewMagickWand();
	MagickReadImage(m_wand,"Winter2.tif");
	MagickSetImageMatte(m_wand,MagickTrue);

	/* Read the PNG which has the alpha layer */
	a_wand = NewMagickWand();
	MagickReadImage(a_wand,"Winter2.png");
	/* Copy the alpha layer from PNG to TIF */
	MagickCompositeImage(m_wand,a_wand,DstInCompositeOp,0,0);
	/* Write it out */
	MagickWriteImage(m_wand,"winter2_cmd.png");

	/* Clean up */
	if(m_wand)m_wand = DestroyMagickWand(m_wand);
	if(a_wand)a_wand = DestroyMagickWand(a_wand);

	MagickWandTerminus();
}
Pete
Post Reply