使用php动态打印图片上的文本
我正在尝试将两段代码组合在一起。第一部分将给定的.jpg图像转换为.png,并将其放入具有相同名称的IMG文件夹中,只是扩展名不同。 代码的第二部分应该在图片上打印“文本”,同时从文件夹IMG(第一部分创建的.png图像)中拍摄图片 我显然做错了什么,因为我最后打印的只是图片的来源,而不是最后使用使用php动态打印图片上的文本,php,Php,我正在尝试将两段代码组合在一起。第一部分将给定的.jpg图像转换为.png,并将其放入具有相同名称的IMG文件夹中,只是扩展名不同。 代码的第二部分应该在图片上打印“文本”,同时从文件夹IMG(第一部分创建的.png图像)中拍摄图片 我显然做错了什么,因为我最后打印的只是图片的来源,而不是最后使用
//FIRST PART
$file = basename($picture, ".jpg");
$file_create = "img/$file.png";
$image = ImageCreateFromJPEG("$picture");
ImageJpeg($image, "img/$file.png");
ImageDestroy($image);
//SECOND PART
header("Content-type: image/png");
$imgPath = "$file_create";
$image = imagecreatefromjpeg($imgPath);
$color = imagecolorallocate($image, 255, 255, 255);
$string = "test";
$fontSize = 3;
$x = 115;
$y = 185;
imagestring($image, $fontSize, $x, $y, $string, $color);
$final=imagejpeg($image);
print "<img src='img/$final' width=150 height=150 valign=middle title='$item' alt='$item'>";
//第一部分
$file=basename($picture,.jpg”);
$file\u create=“img/$file.png”;
$image=ImageCreateFromJPEG($picture”);
ImageJpeg($image,“img/$file.png”);
图像销毁($图像);
//第二部分
标题(“内容类型:图像/png”);
$imgPath=“$file\u create”;
$image=imagecreatefromjpeg($imgPath);
$color=imagecolorallocate($image,255,255);
$string=“test”;
$fontSize=3;
$x=115;
$y=185;
imagestring($image,$fontSize,$x,$y,$string,$color);
$final=imagejpeg($image);
打印“”;
有什么想法吗?这是一个很好的教程
最好写在评论中。