Skip to Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

18.7 Eine transparente Farbe ermitteln und einstellen

Problem

Sie wollen eine der Bildfarben als transparente Farbe einstellen. Wenn das Bild über einen Hintergrund gelegt wird, sieht man den Hintergrund durch den transparenten Teil des Bilds hindurch.

Lösung

Verwenden Sie ImageColorTransparent( ):

$color = ImageColorAllocate($image, $red, $green, $blue);
ImageColorTransparent($image, $color);

Diskussion

Sowohl GIFs als auch PNGs unterstützen transparente Farben, JPEGs jedoch nicht. Um in GD eine transparente Farbe zu beschreiben, verwenden Sie die Konstante IMG_COLOR_TRANSPARENT. Hier sehen Sie beispielsweise, wie man eine gestrichelte Linie erzeugen kann, die zwischen schwarz und transparent wechselt:

// Eine zwei Pixel breite, schwarzweiß gestrichelte ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi

Publisher Resources

ISBN: 9783868993271Purchase book