I know very little of image processing and even less of the terminology used, so please bear with me.
Basically, I want to merge two images together where one of t
So, finally, this should do what you need:
Original image:

Opacity mask:

Overlay:

Output:

The code:
resizeImage(274, 275, Imagick::FILTER_LANCZOS, 1);
// Copy opacity mask
$base->compositeImage($mask, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA);
// Add overlay
$base->compositeImage($over, Imagick::COMPOSITE_DEFAULT, 0, 0);
$base->writeImage('output.png');
header("Content-Type: image/png");
echo $base;
?>
I hope it's right now! Note: In your example it looks like you downscaled the base image, which I didn't (my goal is just to show how the masking is done).