$font = $_SERVER['DOCUMENT_ROOT']."/simfang.ttf"; $font_size=30; $angle = 0; $x = 0; $y = 0+$font_size; $dest_file = "/tmp/a.png"; $delta = $font_size*2/3; $text = trim($_GET['t']); $len = strlen($text); $height = 30; $width = $len * $delta; //$im = imagecreate($width,$height); //gd库 $im = imagecreatetruecolor($width, $height); //gd2库 $white = imagecolorallocate($im,0xFF,0xFF,0xFF); $black = imagecolorallocate($im,0x00,0x00,0x00); imagefill($im, 0, 0, $white); //纯白背景。 //imagecolortransparent($im,$white); //imagecolortransparent() 设置具体某种颜色为透明色 //imagefilledrectangle($im,50,50,150,150,$black); //imagestring($im,5,0,0,"happy every day",$black); //这里的5不是font_size. 而是一种字体。 $ok=imagettftext($im,$font_size,$angle,$x,$y,$black,$font,$text); //这里的x 和 y 是头文字左下角的坐标(与imagestring里面的x和y不同) header("Content-type:image/png"); imagepng($im, $dest_file); //输出到文件 imagepng($im); //标准输出 imagedestroy($im);
You are currently browsing all posts tagged with 'gd'