The project i'm working right now require to use some color randomization. I have atleast 20 asset (text,shape,line,polygon ...etc) that require color randomization ...so i decided to store the randomization RGB in a function so i could keep reusing it and make the PHP file smaller but it didn't work out as expected
<?php
header ('Content-Type: image/jpeg'); // make PHP when access .jpg
$im = imagecreatetruecolor(100, 100); // allocate image with 100 width and 100 height
function randomrgb() {
imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255)); // generate 0 between 255
}
$cbc = randomrgb(); // store randomization on variable first i do not know how to call functions directly
imagefill($im, 0, 0, $cbc); // fill the background with $cbc which is equal to random RGB function
imagejpeg($im);
imagedestroy($im);
?>
I expected the background color to become random but it always black also i do not know how to call the function directly here imagefill($im, 0, 0, $cbc);
without storing it first on variable something like imagefill( $im, 0, 0, randomrgb(); );
i know it possible but i just do not know how .. sorry in advance if this is confusing