이미지 처리 및 GD imagestring
(PHP 4, PHP 5, PHP 7, PHP 8)
imagestring — 문자열을 가로로 그리기
설명
imagestring( GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color ): bool
주어진 좌표에 string
을 그립니다.
매개변수
image
- imagecreatetruecolor()와 같은 이미지 생성 함수 중 하나에서 반환되는 GdImage 객체.
font
- latin2 인코딩(여기서 더 높은 숫자는 더 큰 글꼴에 해당) 또는 imageloadfont()에 의해 반환된 GdFont 인스턴스의 내장 글꼴의 경우 1, 2, 3, 4, 5가 될 수 있습니다.
x
- 왼쪽 상단 모서리의 x 좌표입니다.
y
- 왼쪽 위 모서리의 y 좌표입니다.
string
- 쓸 문자열입니다.
color
- imagecolorallocate()로 생성된 색상 식별자입니다.
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
변경 로그
버전 | 설명 |
---|---|
8.1.0 | font 매개변수는 이제 GdFont 인스턴스와 int를 모두 허용합니다. 이전에는 int만 허용되었습니다. |
8.0.0 | image 는 이제 GdImage 인스턴스를 반환합니다. 이전에는 리소스가 필요했습니다. |
Examples
예제 #1 imagestring() 예제
<?php
// Create a 100*30 image
$im = imagecreate(100, 30);
// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// Write the string at the top left
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor);
// Output the image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
위의 예는 다음과 유사한 결과를 출력합니다.
기타
- imagestringup() - 문자열을 세로로 그리기
- imageloadfont() - 새 글꼴 로드
- imagettftext() - TrueType 글꼴을 사용하여 이미지에 텍스트 쓰기