Frage

ich auf einem captcha image Typ Skript arbeite und ich bin zu wollen jeden Buchstaben Farbe auf meinem Bild wechseln, so weit ich habe es ziemlich viel, außer den Farbwert nicht arbeiten, was ich erwartete

Die Farben in diesem $ multi_text_color Variable sollten die Farben sein, die es zufällig wählt und zeigt, es funktioniert in dem Zufall die Farbe Array-Wert Kommissionierung jedoch sind die Farben, die er auf dem Bild setzen sind 3 Farben nicht, wo in der Nähe zu dem, was ich will, so bin ich etwas falsch hier?

<?PHP
// note this is just the part I am having trouble with, I have taken everything else out that adds line and tilts the letters and stuff so just the color settings are in this bit

// My this part of my script takes each number/letter in a string and makes it a random color to put on the image

// set color values
$multi_text_color = "#FF3E96,#6A5ACD,#90EE90";
// put colors above into an array
$colors = explode(',', $multi_text_color);
// cycle through everything to add the letters/numbers to image
for($i = 0; $i < $characters; ++$i) {
    $idx = rand(0, 2);
    // notice my $colors variable has random number for the color array
    $r = substr($colors[$idx], 1, 2); // shows: f6 or 8d or FF
    $g = substr($colors[$idx], 3, 2); // shows: 3E or 32 or 5c
    $b = substr($colors[$idx], 5, 2); // shows: 96 or 47 or fd 
    $font_color = imagecolorallocate($image, "$r", "$g", "$b");
    // finish it up
    imagettftext($image, $font_size, $angle, $x, $y, $font_color, $this->font, $code{$i});
}
?>
War es hilfreich?

Lösung

Wenn Sie Hex-Zahlen verwenden, müssen Sie sie in Dezimalzahlen konvertieren zuerst.

$font_color = imagecolorallocate($image, hexdec($r), hexdec($g), hexdec($b));

Andere Tipps

imagecolorallocate () nimmt ganze Zahlen als Parameter nicht sticht. Rechnen Sie $ r, $ g und $ b auf ganzzahlige zuerst mit hexdec ().

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top