我想为动态文字创建图像 我的问题是我正在从某个特定目录中读取文件夹名称 所以文件夹名称将是什么,但客户希望该文件夹名称应仅作为图像 所以我想我会在任何唯一名称上放置一个与文件夹同名的图像 但是,如果客户端创建新文件夹,则不希望创建新图像。 那么我怎样才能用PHP做到这一点? 我需要为图像使用一些特定的背景颜色,并且还想为图像中的文本使用一些特定的字体。
答案 0 :(得分:0)
请参阅示例部分中的imagefttext()
答案 1 :(得分:0)
来自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);
?>