[英]How to create images for dynamic text using PHP?
我想為我的動態文本創建圖像。
我的問題是我正在從某些特定目錄中讀取文件夾名稱。
因此,文件夾名稱將是以前的名稱,但客戶端希望該文件夾名稱僅作為圖像出現。
因此,我想將一個與文件夾名稱相同的圖像放置在任何唯一名稱上。
但是,如果客戶創建新文件夾,則他們不想創建新圖像。 那么如何使用PHP做到這一點呢?
我需要為圖像使用某些特定的背景色,還希望為圖像中的文本使用某些特定的字體。
請參閱示例部分中的imagefttext()
從php.net: http://pl2.php.net/manual/en/function.imagettftext.php
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.