PHP Conference Japan 2024

imagestringup

(PHP 4, PHP 5, PHP 7, PHP 8)

imagestringup垂直繪製字串

描述

imagestringup(
    GdImage $image,
    GdFont|int $font,
    int $x,
    int $y,
    string $string,
    int $color
): bool

在指定的坐標垂直繪製一個 string(字串)。

參數

image

一個 GdImage 物件,由影像建立函式之一返回,例如 imagecreatetruecolor()

font

可以是 1、2、3、4、5,代表 latin2 編碼的內建字體(數字越大字體越大),或是由 imageloadfont() 返回的 GdFont 實例。

x

左下角的 x 坐標。

y

左下角的 y 坐標。

string

要繪製的字串。

color

使用 imagecolorallocate() 建立的顏色識別碼。

返回值

成功時返回 true,失敗時返回 false

更新日誌

版本 描述
8.1.0 font 參數現在接受 GdFont 實例和 int(整數)類型;先前只接受 int(整數)類型。
8.0.0 image 現在需要一個 GdImage 實例;先前需要一個有效的 gd resource(資源)。

範例

範例 #1 imagestringup() 範例

<?php
// 建立一個 100*100 的影像
$im = imagecreatetruecolor(100, 100);

// 繪製文字
$textcolor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
imagestringup($im, 3, 40, 80, 'gd library', $textcolor);

// 儲存影像
imagepng($im, './stringup.png');
imagedestroy($im);
?>

上述範例將輸出類似以下的內容

Output of example : imagestringup()

另請參閱

新增筆記

使用者貢獻的筆記 1 則筆記

匿名
21 年前
function imagestringdown(&$image, $font, $x, $y, $s, $col)
{
$width = imagesx($image);
$height = imagesy($image);

$text_image = imagecreate($width, $height);

$white = imagecolorallocate ($text_image, 255, 255, 255);
$black = imagecolorallocate ($text_image, 0, 0, 0);

$transparent_colour = $white;
if ($col == $white)
$transparent_color = $black;

imagefill($text_image, $width, $height, $transparent_colour);
imagecolortransparent($text_image, $transparent_colour);

imagestringup($text_image, $font, ($width - $x), ($height - $y), $s, $col);
imagerotate($text_image, 180.0, $transparent_colour);

imagecopy($image, $text_image, 0, 0, 0, 0, $width, $height);
}
To Top