PHP 文字生成图片并与另一张图片合成一张图片 [问题点数:100分] 收藏
<?php
header (“Content-type: image/png”);
//$str = $_REQUEST[\’str\’] ? $_REQUEST[\’str\’]:”暂\n无\n输\n入”;
$str = “1\n2\n3\n”;
$im = imagecreate(100,120);
$white = imagecolorallocate($im,0xFF,0xFF,0xFF);
imagecolortransparent($im,$white); //imagecolortransparent() 设置具体某种颜色为透明色,若注释
$black = imagecolorallocate($im,0x00,0x00,0x00);
imagettftext($im,15,0,50,40,$black,”simkai.ttf”,$str); //字体设置部分linux和windows的路径可能不同
header(“Content-type:image/png”);
imagepng($im);//文字生成的图片
//两张图片合成方法
$A = “1.png”;
$B = “test.png”;
$x = 20;
$y = 20;
$rh = 50;
$im1 = imagecreatefromstring(file_get_contents($A));
$im2 = imagecreatefromstring(file_get_contents($B));
imagecopymerge($im1, $im2, $x, $y, 0, 0, imagesx($im2), imagesy($im2), $rh);
imageGif($im1);
?>