好的,所以我个人以前不必使用它,但我知道 PHP 有一些内置函数来执行所述任务。在这里你可以找到它。我希望它有帮助:)
http://php.net/manual/en/function.imagettftext.php
好的,所以在做了一些更深入的研究之后,我发现这可能会有所帮助:)
本质上,这是您要使用的表格:
<form action="ProcessImage.php" method="post">
<input type="file" name="im"/>
<input type="text" name="msg"/>
<button type="submit">Submit</button>
这是您要使用的 PHP 代码,称为 ProcessImage.php:
<?php
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = $_POST['im'];
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = $_POST['msg'];
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>