compose over

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
tk1
Posts: 17
Joined: 2011-07-27T05:42:54-07:00
Authentication code: 8675308
Location: Poland

compose over

Post by tk1 »

I'm trying to make with Imagick the same as ImageMagick command:

[code]combine -compose over input.jpg over.gif black&white_mask.gif output.jpg[/code]

The output file should consist of input & over files - depending on mask file.

How can I achieve this?
cheers
tk1
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose over

Post by fmw42 »

tk1
Posts: 17
Joined: 2011-07-27T05:42:54-07:00
Authentication code: 8675308
Location: Poland

Re: compose over

Post by tk1 »

I tried compositeImage() with no success. combine takes 4 files and does the magick. compositeImage() works on 2 files, composite constant and coordinates. I just don't know how put it all together. Could you help me a little bit more?
cheers
tk1
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: compose over

Post by Bonzo »

The problem tk1 is that Imagick is not written or supported by the IM developers and you probably know as much as everybody else that uses the forum!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose over

Post by fmw42 »

combine takes 4 files and does the magick
You said nothing about combine only composite. So please clarify what you need?

If necessary post all your code.

Unfortunately, I do not code Imagick and have only tested a few limited functions.

What version of IMagick and Imagemagick are you using? Perhaps you have the older Imagick. Current version of IMagick is at

http://pecl.php.net/package/imagick/3.1.0RC2
tk1
Posts: 17
Joined: 2011-07-27T05:42:54-07:00
Authentication code: 8675308
Location: Poland

Re: compose over

Post by tk1 »

Guys. I didn't mean to offend anybody. This is Imagick section of the forum. This is why I asked here.

Maybe I misunderstood, but combine.exe command was replaced with composite.exe. Am I right?

Those commands I would like to convert to Imagick.
composite.exe -compose over input.jpg over.gif black&white_mask.gif output.jpg
and
composite.exe -compose over input.jpg over.jpg black&white_mask.gif output.jpg

Images are the same geometry. In both cases I would like to transform input and over images through b&w mask.
Black color from the mask should be replaced with the same part from over image.
White color from the mask should be replaced withthe same part from input image.

I'm trying to write equivalent code in Imagick.

Code: Select all

	try {
		$baseObj = new Imagick($input);		
		$overObj = new Imagick($overlay);
		$maskObj = new Imagick($mask);

		$maskObj->setImageColorspace(imagick::COLORSPACE_GRAY);

		$baseObj->compositeImage($maskObj, Imagick::COMPOSITE_SCREEN, 0, 0);
		$maskObj->negateImage(1);

		if ($baseObj->getImageFormat() == 'GIF') {
			$overObj->compositeImage($maskObj, Imagick::COMPOSITE_SCREEN, 0, 0);
		}
		$baseObj->compositeImage($overObj, Imagick::COMPOSITE_MULTIPLY, 0, 0);

		$baseObj->writeImage($output);

		$baseObj->destroy();
		$maskObj->destroy();
		$overObj->destroy();
	}
	catch(Exception $e) {
	
		echo "Caught Imagick exception: " . $e->getMessage() . ".\n";
	}
This is result of my today's struggling. It looks it does almost what I need. Could anybody suggest what can be done in better way?

I use ImageMagick 6.7.9-4 Q8 and Imagick 3.1.0RC2 and RC1.
cheers
tk1
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose over

Post by fmw42 »

Yes, this is the Imagick forum and the correct place to ask your question. However, many of us know little about it as it was not developed by the Imagemagick team and we understand that it is no longer being maintained. Apart from the references I mentioned earlier, I know little about how to convert the command line into Imagick commands.

Maybe I misunderstood, but combine.exe command was replaced with composite.exe. Am I right?
No, not to my knowledge. If that were the case, it was so long ago as not be usable now. -combine and -composite are two different beasts.

-combine puts individual grayscale images into the R,G,B channels to form one new image.

-composite takes two color images and mixes them together according to the compose method, of which the most common is over (overlaying one on the other).

Today you can use composite ... or the more flexible convert ... -compose ... -composite.

see
http://www.imagemagick.org/script/comma ... hp#combine
http://www.imagemagick.org/script/comma ... hp#compose
http://www.imagemagick.org/script/comma ... #composite
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/layers/
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: compose over

Post by Bonzo »

I am not offended either tk1; I was just letting you know why there may not be the answers you want coming from the forum with regards to Imagick.
Post Reply