<?php
 
$mypic_path = './image3/'.rand(1,340).'.jpg';//图片背景(背景图片名字格式为：.jpg,命名规则：数字.jpg,数字范围就是前面rand()函数里的数字范围)
$font = './wryh.ttf';//字体

//上排的大字
$mypic_nr = mb_substr(urldecode($_GET["k"]),0,13);//文字内容(默认截取10个汉字，靠左对齐)
//下排的小字
//$mypic_nr1 = mb_substr(urldecode($_GET["k"]),12,14);//文字内容(默认截取10个汉字，靠左对齐)

$mypic = imagecreatefromstring(file_get_contents($mypic_path));//创建实例
$white= imagecolorallocatealpha($mypic,0,0,0,70);
$color= imagecolorallocatealpha($mypic,255,255,255,0);//配置颜色参数，透明度(前三个数字为颜色代码，最后一个是透明度)
$imgHeight = imagesy($mypic)/2;//图片高
$imgWidth = imagesx($mypic);//图片宽
$imgWidth = ($imgWidth-mb_strlen($mypic_nr)*35)/2;//不居中就调节60

//上排的大字
imagettftext($mypic,48, 0, $imgWidth-280, $imgHeight-20, $white,$font, ''); //文字背后的白色背景
imagefttext($mypic, 28, 0, $imgWidth, $imgHeight-20, $color, $font, $mypic_nr);//生成文字(第一个参数为字体大小)

//下排的小字
imagettftext($mypic,58, 0, $imgWidth-280, $imgHeight+30, $white,$font, ''); //文字背后的白色背景
imagefttext($mypic, 28, 0, $imgWidth, $imgHeight+30, $color, $font, $mypic_nr1);//生成文字(第一个参数为字体大小)

header('Content-Type: image/jpg');
imagejpeg($mypic);
imagedestroy($mypic);

?>

