PHP/GD - setBrush

Hi,
I am really stuck with this setBrush feature of the GD library.  I'd really like to use an already made jpg/png as the brush when images are drawn in GD, is this possible?

Here is something i have, I know that in the last section of imageline i have to change
so: imageline($im,10,10,30,40,$black); --> becomes --> imageline($im,10,10,30,40,gdsomething); but not sure how to code it.

<?
Header ("Content-Type: image/png");
$im = imagecreate(50,50);
$white=ImageColorAllocate($im,255,255,255);
$black=ImageColorAllocate($im,0,0,0);
imageline($im,10,10,30,40,$black);
imagejpeg($im);
?>
PauliostroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
as far as I can tell, you use this:

$im = imagecreate(50,50);
brush = imagecreatefromjpeg('brush.jpg');
imagesetbrush($im, $brush);
$white=ImageColorAllocate($im,255,255,255);
$black=ImageColorAllocate($im,0,0,0);
imageline($im,10,10,30,40,IMG_COLOR_BRUSHED);

imagedestroy($brush);
imagejpeg($im);

-r-
PauliostroAuthor Commented:
Pefect! Thanks Roonaan.
But is it possible to use a png-24 brush image (with transparent background) so that when its drawn using this in GD it appears as if its not overlapping all the points/lines and looks like a nice clean line?

Thanks
RoonaanCommented:
Try this:

$brush = imageCreateFromPng('mypng.png');

And when transparency doesn't show up, try adding these lines

imageAlphaBlending($brush, true);
imageSaveAlpha($brush, true);

I am not sure though if the last two lines should be applied on $brush, or on $im. You might have to play around a little.

-r-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.