imagefttext()没有工作有什么想法?

时间:2016-08-23 11:01:25

标签: php

这是例子:

            $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`

1 个答案:

答案 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);

?>