大家好,我正试图在运行时在图像上写一个字符串,为此,我使用了来自GD的imagestring
,但没有得到所需的输出,相反,它的给出遇到了他的错误:
imagegif(): Unable to open 'temp/textImage.gif' for writing: No such file or directory in … on line 157 Warning:
然而,这段代码在imagefttext()
函数中运行得很好,但由于我的托管提供商heroku
不支持freetype库,所以这就是我切换的原因。
$message = “Hello World”;
//Image Processing:
$imageUrl = "image.gif";
$imageId = imagecreatefromgif($imageUrl);
$angle = 0;
$xCord = 4;
$yCord = 40;
$imageColor = imagecolorallocate($imageId, 0, 0, 0);
$fontUrl = "GOTHIC.TTF";
$imageText = "HELOOOO";
$imageTextLnght = strlen($imageText);
$fontSize = (500 / $imageTextLnght) + 5;
$imageFont = 1;
//imagefttext($imageId, $fontSize, $angle, $xCord, $yCord, $imageColor, $fontUrl, $imageText);
imagestring($imageId, 5, $xCord, $yCord, $imageText, $imageColor);
//header('Content-Type: image/gif');
//Saving Image With Text:
$textImage = 'temp/textImage.gif';
imagegif($imageId, $textImage);
imagedestroy($imageId);
请帮我一下:感谢
确保temp
存在,或使用mkdir
创建它。
通常,尝试创建文件时出现错误Unable to open .. No such file or directory
意味着该目录不存在。