Hello everyone I am trying to write a string on image during runtime and for this purpose I am using imagestring from GD, but am not getting the required output instead its giving met his error:
imagegif(): Unable to open 'temp/textImage.gif' for writing: No such file or directory in … on line 157 Warning:
However this same code was working fine with imagefttext() function, but as my hosting provider heroku does not support freetype library so that’s why ive to switch.
$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);
Kindly help me with this:
Thankyou
Make sure that
tempexists, or create it withmkdir.Usually the error
Unable to open .. No such file or directorywhen trying to create a file means that the directory doesn’t exist.