PHP图像 - 将图像添加到使用PHP创建的另一个图像上
Basically I have to work with a ID Card PHP thing that requires me to add the name of a participant and upload a picture. I have a basic template for the ID Card and I'm using PHP to add the name. I have to add the picture of the participant on a particular spot. The name is working but I cannot add a picture of the participant over the generated PHP image. Here's my code:
How should I go about adding the picture over the PHP generate image.
Sorry if this is confusing :/
基本上我必须使用ID卡PHP的东西,要求我添加参与者的名字并上传 图片。 我有一个ID卡的基本模板,我正在使用PHP来添加名称。 我必须在特定地点添加参与者的图片。 该名称正在运行,但我无法在生成的PHP映像上添加参与者的图片。 这是我的代码: p>
http://chopapp.com/#arcqwgf4 p>
我应该如何在PHP生成图像上添加图片。 p>
对不起,如果这令人困惑:/ p> DIV>
You are already most of the way there using GD, what you need to do is use imagecopymerge to draw one image on top of the other at a specified point on the base image. PHP.net has quite a few examples on the linked page.
Use the Imagick for things like these. There is a method named combineImages()
with which you can achieve your goal.
You can do it with imagecopyresampled method in php.
I created an example here: http://artuc.my.phpcloud.com/artuc/ type name, id and select an image to place it.
Here is the code i used:
header('Content-Type: image/jpeg');
$canvasImage = imagecreatefromjpeg('sample.jpg');
$bgcolor = imagecolorallocate($canvasImage, 255, 255, 255);
imagefill($canvasImage, 0, 0, $bgcolor);
//Place person picture
$bgImage = $_POST['idPic'];
$img = imagecreatefromjpeg($bgImage);
$imageSize = getimagesize($bgImage);
imagecopyresampled($canvasImage, $img, 15, 17, 0, 0, $imageSize[0], $imageSize[1], $imageSize[0], $imageSize[1]);
$fontFile = "Arial.ttf";
//Place person name
$black = imagecolorallocate($canvasImage, 0, 0, 0);
imagettftext($canvasImage, 18, 0, 220, 35, $black, $fontFile, $_POST['idName']);
//Place person id
$black = imagecolorallocate($canvasImage, 0, 0, 0);
imagettftext($canvasImage, 18, 0, 220, 75, $black, $fontFile, $_POST['idNum']);
//Save Image
imagejpeg($canvasImage);
imagedestroy($canvasImage);