Good morning!

I have been playing around with the PHP graphics functions in an attempt to build a graphic using several external PNG files and layering them, one on top of the other. All the external PNG files are the same size and saved with white as transparent. My plan is to use a base graphic (a speedometer face), overlay it with another graphic (an arrow pointing at a set angle), overlay those two with another graphic (a different arrow at a different angle), etc...with up to 5 layers. The base remains the same in each case, but the arrows use a subset of all the possible arrow directions.

First I tried just creating the 2 resourses and then outputting them (Code Sample 1, below). But that just outputs the first file. (The second test file is a wider-thinner red box to make sure I am not just covering one graphic with the other.)

Then I tried using imagecopy, both without and with imagelayereffect($image,IMG_EFFECT_OVERLAY), and that writes the second image on the first, but seems to make the first image all black (while keeping the original solid color of the second image). (Code Sample 2)

I am at a loss as to what to try next. Being very new to to PHP, any brilliant suggestions, code snippets, completed packages doing what I want and a dozen things I have not yet thought of, would all be greatly appreciated!

Thank you for your time, efforts and expertise!
aloha ah

Code Sample 1: Simple Create and Write
$ImgBaseStr = "C:/AppServ/www/img/base.png";
$ImgTopStr = "C:/AppServ/www/img/test.png";
$ImgBase = imagecreatefrompng($ImgBaseStr) or die("Cannot Initialize $ImgBaseStr");
$ImgTop = imagecreatefrompng($ImgTopStr) or die("Cannot Initialize $ImgTopStr");
header("Content-Type: image/png");
imagepng($ImgBase);
imagepng($ImgTop);
imagedestroy($ImgBase);
imagedestroy($ImgTop);

Code Sample 2: Using Imagecopy
$ImgBaseStr = "C:/AppServ/www/img/base.png";
$ImgTopStr = "C:/AppServ/www/img/test.png";
$ImgBase = imagecreatefrompng($ImgBaseStr) or die("Cannot Initialize $ImgBaseStr");
$ImgTop = imagecreatefrompng($ImgTopStr) or die("Cannot Initialize $ImgTopStr");
$ImgX = imagesx($ImgBase);
$ImgY = imagesy($ImgBase);
imagelayereffect($ImgTop, IMG_EFFECT_OVERLAY);
imagecopy ($ImgBase, $ImgTop, 0, 0, 0, 0, $ImgX, $ImgY);
header("Content-Type: image/png");
imagepng($ImgBase);
imagedestroy($ImgBase);
imagedestroy($ImgTop);

    Write a Reply...