I am using the PHPImageWorkshop library to layer up transparent images, (which is one of the things it is supposed to excel at, so I must be doing it wrong)!
When I just specify the base layer, (a transparent PNG logo), everything works as expected, see code:
<?php
use PHPImageWorkshop\ImageWorkshop;
require_once('lib/PHPImageWorkshop/ImageWorkshop.php');
$base_layer = ImageWorkshop::initFromPath( __DIR__.'/img/bg.png' );
$dirPath = dirname(__FILE__).'/output/';
$filename = "file.png";
$base_layer->save( $dirPath, $filename, false, null, 95 );
?>
<img src="/output/file.png">
... the result is a transparent PNG with my specified background image, as expected, (I'm not really doing anything here except copying the image).
The problem occurs when I try to add a smaller image on top of the background layer, instead of overlaying it, it appears to overwrite my background image, replacing it completely?
Here, I try to create a small grey square, (100 x 100), and place it in the middle of my background logo, (using my existing code):
<?php
use PHPImageWorkshop\ImageWorkshop;
require_once('lib/PHPImageWorkshop/ImageWorkshop.php');
$base_layer = ImageWorkshop::initFromPath( __DIR__.'/img/bg.png' );
// ADDED 2 LINES--------------------------------------------------
$layer_two = ImageWorkshop::initVirginLayer( 100, 100, 'CCCCCC' );
$base_layer->addLayerOnTop( $layer_two, 0, 100, 'MT' );
$dirPath = dirname(__FILE__).'/output/';
$filename = "file.png";
$base_layer->save( $dirPath, $filename, false, null, 95 );
?>
<img src="/output/file.png">
Now my background logo is no longer visible, and I have a small grey square on a transparent layer, the size that my background image was.
What am I doing wrong, please?
Thanks for looking...