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.

I have a 'main' image of a kitchen with a roughly rectangular transparency layer, with some faint contents representing the reflection of a window behind the viewer. I'm trying to overlay onto this a mostly solid image to fit into the rectangular space, so that it appears to have the reflection visible in it. This overlay image has perspective distorsion to make it fit into the 3d scene, so there are transparent triangles along the top and bottom edges.

However compositing via Imagick causes colour distorion, presumably where the colour value of pixels in the overlay image are being added to the faint colour values in the transparency area in the main image: https://imgur.com/a/T7SR2nZ

I would think that COMPOSITE_BLEND would be right, but this causes the transparent areas of the overlay image to obsure the main image: https://imgur.com/a/xUnsEwv (see how the bottom-left corner of the London image is overlapping the shiny metal pot ... with COMPOSITE_ADD this effect does not happen)

Update: I've a strong feeling I need to create a mask based on the transparency of the main image.. that would give me a mask shaped like the rectangular area but, crucially, with cutouts for the shiny pot on the stove for example. Then I need to crop my overlay image using this mask, to remove bits that would overlay elements on the main image (i.e. the shiny pot). Then COMPOSITE_BLEND would probably do the job beautifully.

@snibgo I provided a screenshot. Just create two layers and position the smaller image to be overlaid 'underneath' the main image. However, achieving an effect in a graphics package is a different process to doing it via Imagick, e.g. in the first thread I linked to above, http://www.imagemagick.org/discourse-se ... hp?t=19116, he also says he achieved it in Photoshop but was having trouble via the imagemagick CLI.

If your point is "if you can do it in the GIMP so easily it must be easy in Imagick" then I would initially agree with you, yet my simple attempts have failed. GIMP seems to be doing a pretty straightforward "obscure the underlaying image with pixels from the image on top" yet none of the COMPOSITE_* operators I've tried have achieved the same result.

Your comment did make me think perhaps I should start with the overlay image, sized the same size as the main image, and then overlay the main image on top of it i.e. perform the operation in reverse order to what I was doing before, but again this doesn't work, with _ADD I still get the rainbow effect (because the pixel values are still being combined in undesirable way) and _BLEND causes the overlay image's pixels to corrupt bits of the main image I don't want them to (e.g. the shiny pot).

Gimp's "Mode Normal" corresponds to IM's "-compose Over" so if you like the Gimp result, I suggest you use "-compose Over", in the same order as Gimp, with the river scene first then the kitchen photo.

Aha! COMPOSITE_OVER does indeed do the trick, if I start with the overlay image, and compose the main image over it. So I start with a different overlay image, this time one that's the same dimensions as the main image (1000x1000 pixels):