Skip to Main 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.5 Zentrierten Text zeichnen

Problem

Sie wollen Text in der Mitte des Bilds zeichnen.

Lösung

Finden Sie die Größe des Bilds und des Textrahmens heraus. Mit diesen Koordinaten errechnen Sie die richtige Stelle zum Zeichnen des Texts.

Bei eingebauten GD-Schriftarten verwenden Sie die Funktion pc_ImageStringCenter( ), die in Listing 18.1 vorgestellt wird.

function pc_ImageStringCenter($image, $text, $font) { // Schriftgrößen. $width = array(1 => 5, 6, 7, 8, 9); $height = array(1 => 6, 8, 13, 15, 15); // Bildgröße ermitteln. $xi = ImageSX($image); $yi = ImageSY($image); // Textgröße ermitteln. $xr = $width[$font] * strlen($text); $yr = $height[$font]; // Zentrierung berechnen. $x = intval(($xi - $xr) / 2); $y = intval(($yi - $yr) / 2); return array($x, ...
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
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book