function rndrgb($color){ //Генерация случайного оттенка выбранного цвета
$rnd = mt_rand(100,255);
switch ($color){
case "red": return "rgb(".$rnd.",0,0)";
case "green": return "rgb(0,".$rnd.",0)";
case "blue": return "rgb(0,0,".$rnd.")";
}
return "rgb(0,".$rnd.",0)";
}
<?php
include ("functions.php");
$color_arr= [
"red",
"green",
"blue",
];
shuffle($color_arr);
$str_arr = ["OPOP","dsfs","sdhhhhhh"];
$img = imageCreateTrueColor(500,40);
imagefilledrectangle($img,0,0,560,480,imagecolorallocate($img,192,192,192));
imageantialias($img,true);
$x = 10;
$y = 10;
$dx = 10;
$dy = 10;
$rgb = 0;
for ($i=0;$i<count($str_arr);$i++){
for ($j=0;$j<strlen($str_arr[$i]);$j++){
/*ВЫБОР ОТТЕНКА*/
switch( $color_arr[$i % count($color_arr)]){
case "red": $rgb = imagecolorallocate($img, 0+rndrgb("red"),0, 0); break;
case "green": $rgb = imagecolorallocate($img, 0, 0+rndrgb("green"), 0); break;
case "blue": $rgb = imagecolorallocate($img, 0, 0, 0+rndrgb("blue")); break;
}
/*КОНЕЦ ВЫБОРА ОТТЕНКА*/
imagefilledrectangle($img,$x,$y,$x+$dx,$y+$dy,$rgb); //<-- Не красятся
$x+=20;
}
$x+=20;
}
header("Content-Type: image/gif");
imageGif($img);
imagedestroy($img);
?>
В $rgb оказывается ноль, а должны быть случайные значения, в итоге квадраты не закрашиваются цветами.