이미지 처리 및 GD imageftbbox

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

imageftbbox — freetype2를 통해 글꼴을 사용하여 텍스트의 경계 상자 제공


설명

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

이 함수는 FreeType 텍스트의 경계 상자를 픽셀 단위로 계산하여 반환합니다.

메모: PHP 8.0.0 이전에 imageftbbox()는 옵션을 추가로 지원하는 imagettfbbox()의 확장된 변형이었습니다. PHP 8.0.0부터 imagettfbbox()imageftbbox()의 별칭입니다.


매개변수

size
글꼴 크기(포인트).
angle
string이 측정될 각도(도)입니다.
font_filename
트루타입 글꼴 파일의 이름(URL일 수 있음). PHP가 사용하는 GD 라이브러리 버전에 따라 파일 이름에 '.ttf'를 추가하고 라이브러리 정의 글꼴 경로를 따라 검색하여 선행 '/'로 시작하지 않는 파일 검색을 시도할 수 있습니다.
string
측정할 문자열입니다.
options

options에 대한 가능한 배열 인덱스

Key Type Meaning
linespacing float 그리기 줄 간격을 정의합니다.

반환 값

imageftbbox()는 텍스트의 경계 상자를 만드는 4개의 점을 나타내는 8개의 요소가 있는 배열을 반환합니다.

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

점은 angle에 관계없이 텍스트를 기준으로 하므로 "왼쪽 위"는 왼쪽 상단 모서리에서 텍스트를 가로로 보는 것을 의미합니다.

실패하면 false가 반환됩니다.


Examples

예제 #1 imageftbbox() 예제

                  
<?php
// Create a 300x150 image
$im = imagecreatetruecolor(300, 150);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);

// Set the background to be white
imagefilledrectangle($im, 0, 0, 299, 299, $white);

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

// First we create our bounding box
$bbox = imageftbbox(10, 0, $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($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group');

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

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

메모

참고: 이 함수는 PHP가 자유형 지원(--with-freetype-dir=DIR)으로 컴파일된 경우에만 사용할 수 있습니다.


기타

  • imagefttext() - FreeType 2를 사용하여 글꼴을 사용하여 이미지에 텍스트 쓰기
  • imagettfbbox() - TrueType 글꼴을 사용하여 텍스트의 경계 상자 제공