imagick module 3.4.3 (2018-07-24)
system: Fedora Linux
Linux uberneek.localdomain 4.17.11-100.fc27.x86_64 #1 SMP Mon Jul 30 15:22:33 UTC 2018 x86_64
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.
I think my problem is the COMPOSITE_* constant I'm using, currently COMPOSITE_ADD, but I've tried every one I can find (at http://php.net/manual/en/imagick.constants.php) and none seem to achieve the desired effect.
This works fine in The GIMP: https://imgur.com/a/ukDzAV6 (you can see a kind of square pattern over the image of London)
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)
My source files are:
transparent_splashback.png: https://imgur.com/a/9PRxi2p
img.png: https://imgur.com/a/z1C0PLj
A small test program that demonstrates my approach:
Code: Select all
<?php
// Demonstrates problem overlaying image onto main image so it shows through
// the transparency layer of the main image
// Load the main image
$mainImg = new Imagick();
$mainImg->readImage('transparent_splashback.png');
// Load the overlay image
$overlayImg = new Imagick();
$overlayImg->readImage('img.png');
$compositeX = 317; // top left corner in main image
$compositeY = 234;
// Overlay them
$mainImg->compositeImage($overlayImg, Imagick::COMPOSITE_ADD, $compositeX, $compositeY);
// Return the result as a data stream
$blob = $mainImg->getImageBlob();
file_put_contents('out.png', $blob);
echo "Wrote out to out.png OK.";
Thank you so much for reading! Any ideas would be welcome.
[EDIT: to fix misleading subject]