<?php // Set the content-type header("Content-type: image/jpeg"); // Create the image $im = imagecreatetruecolor(400, 300); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); imagefilledrectangle($im, 0, 0, 399, 299, $white); // The text to draw $a=array('是','个','大','帅','哥','的','家','吕','朴','作','者'); $tmp=array_rand($a,4); $text =$a[$tmp[0]].$a[$tmp[1]].$a[$tmp[2]].$a[$tmp[3]];// '中文'; // Replace path by your own font path $font = 'simhei.ttf'; //$text=iconv('gb2312','utf-8','面对对象'); // Add some shadow to the text imagettftext($im, 20, 30, 21, 200, $grey ,$font,$a[$tmp[0]]); imagettftext($im, 20, -30, 61, 200, $grey,$font, $a[$tmp[1]]); imagettftext($im, 20, 30, 101, 200, $grey, $font,$a[$tmp[2]]); imagettftext($im, 20, -30, 141, 200, $grey, $font,$a[$tmp[3]]); // Using imagepng() results in clearer text compared with imagejpeg() imagejpeg($im); imagedestroy($im); ?>