The image needs to be created with imagecreatetruecolor(), you must use imagefill() instead of imagefilledrectange(), and you need to call imagesavealpha(). No other combination of functions calls seems to produce the intended results.

Here is a function to generate a gradient.You specify width, heigth and 4 colors (of the 4 corners).

An image handle of the gradient image will be returned.You can copy the returned image onto another image using imageecopy.This can be helpful if you want to generate a shadow for example.("Glow effect example": Generate 8 gradients, one for each side and one for each corner. The outer side of the gradients have the background color and the inner sides have a bright color such as white.)

But beware: This function is not optimized for performance, it might become slow on big images. For shadows, better cache the generated gradients.

I spend more then two hour to find a function that can fill a pattern or file as background instead of color. but i can't find. so i develop the following function. i though this function will save time who need it...

Function will get four parameter1. Main Image Identifier2. Pattern Image Identifier3. Final Image Width4. Final Image Height

If you set final image width or height is less then main image width or height then you may get wrong result

<?php

function fill_with_patternfile($p_main_im, $p_patternfile_im, $p_width, $p_height){$pimiX=$p_patternfile_im;$pw=imagesx($pimiX);$ph=imagesy($pimiX);$targetImageIdentifier=imagecreatetruecolor($p_width,$p_height); if($pw<$p_width && $ph<$p_height){ for($pX=0;$pX<$p_width;$pX+=$pw){ for($pY=0;$pY<$p_height;$pY+=$ph){imagecopy($targetImageIdentifier,$pimiX,$pX,$pY,0,0,$pw,$ph); } } }else imagecopy($targetImageIdentifier,$pimiX,0,0,0,0,$pw,$ph);$w=imagesx($p_main_im);$h=imagesy($p_main_im);$nX=0; if($w<$p_width) $nX=intval(($p_width-$w)/2);$nY=0; if($h<$p_height) $nY=intval(($p_height-$h)/2);imagecopy($targetImageIdentifier,$p_main_im,$nX,$nY,0,0,$w,$h); return $targetImageIdentifier;}// If you want to use a gif or png file as// pattern file you need to change function below :)$pattern_im=imagecreatefromjpeg('logo.jpg');// If you want to use a gif or png file as// main file you need to change function below :)$main_im=imagecreatefromjpeg('r2.jpg');// call the function width 500 and height 500// if your width and height is less then main images// width and height then you can't understand any change!$final=fill_with_patternfile($main_im, $pattern_im, 500, 500);// view the image and destroy all instanceheader('Content-type: image/jpeg');imagejpeg($final);imagedestroy($final);imagedestroy($main_im);imagedestroy($pattern_im);exit();

This function does not seem to work with images already been transparent. If you fill at x=0, y=0, and there are still transparent parts that you did
not reach with your fill, they change to a different color.

The ImageColorSet function seems to be the solution, but i can't work with transparancy.

This function, cannot deal with transparencies. So you need to use imagecolorallocate instead of imagecolorallocatealpha.Thus, be careful with color variables that allready set with imageallocatecoloralpha because this can slow-down or hang-up your system.