imageftbbox

(PHP 4 >= 4.0.7, PHP 5, PHP 7, PHP 8)

imageftbboxGive the bounding box of a text using fonts via freetype2

Beschreibung

imageftbbox(
    float $size,
    float $angle,
    string $font_filename,
    string $string,
    array $options = []
): array|false

This function calculates and returns the bounding box in pixels for a FreeType text.

Hinweis:

Prior to PHP 8.0.0, imageftbbox() was an extended variant of imagettfbbox() which additionally supported the options. As of PHP 8.0.0, imagettfbbox() is an alias of imageftbbox().

Parameter-Liste

size

Die Schriftgröße in Punkten.

angle

Angle in degrees in which string will be measured.

font_filename

The name of the TrueType font file (can be a URL). Depending on which version of the GD library that PHP is using, it may attempt to search for files that do not begin with a leading '/' by appending '.ttf' to the filename and searching along a library-defined font path.

string

The string to be measured.

options

Possible array indexes for options
Key Type Meaning
linespacing float Defines drawing linespacing

Rückgabewerte

imageftbbox() returns an array with 8 elements representing four points making the bounding box of the text:

0 lower left corner, X position
1 lower left corner, Y position
2 lower right corner, X position
3 lower right corner, Y position
4 upper right corner, X position
5 upper right corner, Y position
6 upper left corner, X position
7 upper left corner, Y position

The points are relative to the text regardless of the angle, so "upper left" means in the top left-hand corner seeing the text horizontally.

On failure, false is returned.

Beispiele

Beispiel #1 imageftbbox() example

<?php
// Create a 300x150 image
$im imagecreatetruecolor(300150);
$black imagecolorallocate($im000);
$white imagecolorallocate($im255255255);

// Set the background to be white
imagefilledrectangle($im00299299$white);

// Path to our font file
$font './arial.ttf';

// First we create our bounding box
$bbox imageftbbox(100$font'The PHP Documentation Group');

// This is our cordinates for X and Y
$x $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
$y $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;

imagefttext($im100$x$y$black$font'The PHP Documentation Group');

// Output to browser
header('Content-Type: image/png');

imagepng($im);
imagedestroy($im);
?>

Anmerkungen

Hinweis: Diese Funktion ist nur verfügbar wenn PHP mit Freetype unterstützung (--with-freetype-dir=DIR) kompiliert wurde

Siehe auch

  • imagefttext() - Write text to the image using fonts using FreeType 2
  • imagettfbbox() - Ermittle das umgebende Rechteck eines Textes unter Verwendung von True-Type Schriftarten

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Spielplan für 4 Gruppen zu je 6 Teams auf 2 Feldern

Hey, hallöchen! Du musst die Spiele so durchgehen, dass die Platzierung kontrolliert wechseln, dass jedes Team auf den Plätzen spielt. Hier ist ...

Geschrieben von derH0st am 10.06.2024 14:26:06
Forum: PHP Developer Forum
Does Google ignore common words?

Our website is optimized for "mock web services" and "web service mocks," but Google Webmaster doesn't recognize "web services" (or its variations ...

Geschrieben von TahuluLimia am 10.06.2024 12:26:02
Forum: Webmaster
How to overcome Safari's iframe cookie block?

Seeking an elegant solution for cross-domain cookie sharing in my project. Safari's default iframe session cookie block is a hurdle. While the san ...

Geschrieben von BrovtalGemini am 10.06.2024 10:14:21
Forum: HTML, JavaScript, AJAX, jQuery, CSS, Bootstrap, LESS
Helfen! Doppelte Bestelleinträge in meiner Verkaufstabelle

Identifizieren Sie doppelte Einträge: Manuelle Überprüfung: Durchsuchen Sie die Tabelle "Sales" nach doppelten Einträgen (zeitaufwändig & u ...

Geschrieben von LillianFelly am 04.06.2024 12:46:18
Forum: SQL / Datenbanken