這是使用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