我目前正在做一个小项目。对于这个项目,我需要一张带有文字的照片(让机器人更难找出文字)。
我正在听从 this 的建议回答,但是 imagettftext
使用真正的字体,这在我的情况下是不可能的。
因此,我寻找替代方案并找到了 imagestring
.
所以我解决这个问题的方法是这样的:
<?php
function randExer() {
//Creating random (simple) math problem
$arr = array("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten");
$item1 = $arr[array_rand($arr)];
$item2 = $arr[array_rand($arr)];
$random = $item1 . " + " . $item2;
//Saving created math problem for later
file_put_contents("exercise.txt", $random);
//Creates a black picture with width=200 and height = 50
$img = imagecreatetruecolor(200, 50);
//uses RGB-values to create a useable color
$white = imagecolorallocate($img, 255, 255, 255);
//Adds white-colored text
$var = imagestring($img, 5, 18, 18, $random . " = ?", $white);
//Save image
imagejpeg($img, "exercise.png", -1);
};
?>
这是有效的,结果如下所示:问题
有没有办法以一定的角度旋转文本?
最佳答案
您可以使用 https://www.php.net/manual/en/function.imagerotate.php图像旋转
例如
...
//Adds white-colored text
$var = imagestring($img, 5, 18, 18, $random . " = ?", $white);
$rotate = imagerotate($img, 10, 0);
//Save image
imagejpeg($rotate, "exercise.png", -1);
...
调整角度的第二个参数
关于php - 使用 imagestring() 旋转文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63700672/