这是例子:
$im = imagecreatetruecolor(300, 100);
$red = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
// Make the background red
imagefilledrectangle($im, 0, 0, 299, 99, $red);
// Path to our ttf font file
$font_file = 'Oswald-Regular.TTF';
// Draw the text 'PHP Manual' using font size 13
imagefttext($im, 13, 0, 105, 55, $black, $font_file, 'PHP Manual');
// Output image to the browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
这是结果: 就这个
PNGIHDR,d c pHYs + /IDATx 1 0 }: [ v& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& ; !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& !fB b& ! fB b& !fB b& !fB b& !fB b& ! ǶyXIEND B`
答案 0 :(得分:0)
@Klevis Cipi - 这是我运行的代码,它产生了图像。在你打电话imagepng
之前,没有任何输出?
<?php
$sText='Stackoverflow';
$fontsize=18;
$oImg = imagecreatetruecolor(300, 100);
$oRed = imagecolorallocate($oImg, 255, 0, 0);
$oBlack = imagecolorallocate($oImg, 0, 0, 0);
// Make the background red
imagefilledrectangle($oImg, 0, 0, 300, 100, $oRed);
// Path to our ttf font file
$font_file = 'c:/wwwroot/inc/fonts/arial.ttf';
imagefttext($oImg, $fontsize, 0, 50, 55, $oBlack, $font_file, $sText );
// Output image to the browser
header('Content-Type: image/png');
imagepng($oImg);
imagedestroy($oImg);
?>