Page 1 of 1
Overlay an image on an image (background on a graph)
Posted: Fri Dec 13, 2002 12:47 am
by travdes
How do you overlay a background image on a graph? I'm creating a bar graph, and would like to have a background image, but havent found anything in the API to create an image, on top of another image.
Posted: Fri Dec 13, 2002 12:58 am
by volka
you might use
imagecreatefrompng() (or similar) and then draw on your background-image.
setting
imagecolortransparent() is regarded by
imagecopymerge() if you have to merge two images
Code: Select all
<?php
header('Content-type: image/png');
// a solid-blue image
$back = imagecreate(30,30);
$col1 = imagecolorallocate($back, 0,0,255);
// a solid-black image
$add = imagecreate(30,30);
$col1 = imagecolorallocate($add, 0,0,0);
// with some white text on it
$col2 = imagecolorallocate($add, 255,255,255);
imagestring($add, 1, 5, 10, "test", $col2);
// merge both
imagecolortransparent($add, imagecolorat($add, 0,0));
imagecopymerge($back, $add, 0, 0, 0, 0, imagesx($add), imagesy($add), 99);
// output
imagepng($back);
?>
Sweet...
Posted: Fri Dec 13, 2002 9:42 am
by travdes
Thanks for your help. I'll have to remember not to use phpbuilder to look up the functions, because that one doesnt exist on phpbuilder but does on php.net.
Redraw problems
Posted: Sun Dec 15, 2002 10:10 pm
by travdes
For some reason sometimes it draws 'imagefilledrectangle' properly and other times, not. For example, I've attached an image, the backdrop is an example of it not working (the bars are almost the same colour as the background, and the image on the side is an example of it working.
I first create 'image A', the merge 'image B' (background image', then I create all the plot lines, bars etc on top of 'image A'. This doesnt work at all if I set transition to 99, I reset it to the 75 range, and it works some of the times.
As you can see from the images, the bars are getting drawn in both, the colours just arent correct all the time. Does anyone have any idea what might be causing this?
