imagecolorallocate mit HTML-Farbcodes

Ich hab hier mal eine kleine Funktion geschrieben mit der man Farben direkt aus HTML-Farbcodes erstellen kann.

function allocate_color_from_hex($handle, $hex) {
	if (strlen($hex) == 4) $hex = '#' . $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
 
	$red   = hexdec(substr($hex, 1, 2));
	$green = hexdec(substr($hex, 3, 2));
	$blue  = hexdec(substr($hex, 5, 2));
 
	return imagecolorallocate($handle, $red, $green, $blue);
}

Benutzung:

$color = allocate_color_from_hex($picture, "#123456");

Vielleicht ist die ja nicht nur für mich nützlich. :-)

Informationen

1 Stern2 Sterne3 Sterne4 Sterne5 Sterne (Keine Bewertung bis jetzt)
Loading ... Loading ...
Schlagwörter: ,
Ansichten: 1.237

Kommentare

Keine Kommentare bis jetzt.

Kommentar schreiben

XHTML: Folgende Elemente sind erlaubt: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Angetrieben durch Wordpress Thema erstellt von Antu