Page 1 of 1

combining two images

Posted: 2007-02-08T07:56:51-07:00
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

Re: combining two images

Posted: 2007-02-08T11:21:02-07:00
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.

Re: combining two images

Posted: 2007-02-09T17:44:33-07:00
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.

Re: combining two images

Posted: 2007-02-10T20:42:39-07:00
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.

Re: combining two images

Posted: 2007-02-11T12:18:43-07:00
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

Re: combining two images

Posted: 2007-02-12T02:59:26-07:00
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

Re: combining two images

Posted: 2007-02-17T12:48:11-07:00
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.

Re: combining two images

Posted: 2007-03-06T02:47:58-07:00
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

Re: combining two images

Posted: 2007-03-06T10:38:38-07:00
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