这是使用PHP GD库完成的。
您需要一张PNG图像才能开始。你可以选择任何东西,例如100 x 100 canvas.png
,只有白色的东西(所以你可以读取黑色文字)。
也找到一个字体来写文字。将其保存在与脚本相同的目录中。
<?php
// fetch the text to write
$first = $_REQUEST['first'];
$last = $_REQUEST['last'];
$email = $_REQUEST['email'];
$address = $_REQUEST['address'];
$city = $_REQUEST['city'];
header('Content-type: image/png');
$canvas = imagecreatefrompng('canvas.png'); // let's suppose canvas.png is a 100x100 pure white PNG
$black = imagecolorallocate($canvas, 0, 0, 0); // create a color object (choosing black for a white canvas!)
$font_path = './myfont.ttf'; // select font
// imagettftext (resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text)
imagettftext($canvas, 10, 0, 10, 10, $black, $font_path, $first); // place text on canvas
imagettftext($canvas, 10, 0, 10, 25, $black, $font_path, $last); // place text on canvas
imagettftext($canvas, 10, 0, 10, 40, $black, $font_path, $email); // place text on canvas
imagettftext($canvas, 10, 0, 10, 55, $black, $font_path, $address); // place text on canvas
imagettftext($canvas, 10, 0, 10, 60, $black, $font_path, $city); // place text on canvas
imagepng($canvas); // send image to browser
imagedestroy($canvas); // clear memory
?>
检查这个http://stackoverflow.com/questions/8429011/how-to-write-the-text-on-top-of-image-in-html5-canvas – danielarend
这里有一个小文章,你可以(https://en.m.wikipedia.org/wiki/POST_(HTTP)) – Jek
请参阅[使用PHP创建PNG](http://php.net/manual/) EN/image.examples-png.php)。 – showdev