<?php header('Content-type: image/png'); $im = imagecreatetruecolor(400, 300); //創建畫布 $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); //輸出一個白色填充的矩形背景 // ////string iconv ( string $in_charset , string $out_charset , string $str ) ////將字符串 str 從 in_charset 轉換編碼到 out_charset。 // $text = iconv('gb2312','utf-8','show'); // ////設置字體 $font = 'C:\Windows\Fonts\msyh.ttc'; // imagettftext($im, 20, 0, 12, 21, $grey, $font, $text); //輸出一個灰色字符串作為陰影 //imagettftext($im, 20, 0, 10, 20, $black, $font, $text); //輸出一個黑色字符串 //ob_clean(); imagepng($im); imagedestroy($im);
設置字體的時候要寫路徑,不然就畫不出來了