I'm trying to create an image from google's php appengine that contains some text rendered using the imagettftext php function. I have to especify a font file name and it's path to the function but i don't know how to access my static fonts directory from php script as scripts are stored separately from static files when i deploy the application.
This is the relevant code from my php script:
header("Content-type: image/png");
$image = imagecreatetruecolor($imgWidth, $imgHeight);
imagealphablending($image, false);
$transparency = imagecolorallocatealpha($image, 0, 0, 0, 127);
$black = imagecolorallocatealpha($image, 0,0,0, 0);
$font = './font/Allerta-Regular.ttf';
imagefill($image, 0, 0, $transparency);
imagesavealpha($image, true);
imagealphablending($image, true);
imagettftext($image, $fontSize, $angle, 100, 100, $black, $font, "Test text");
imagepng($image);
imagedestroy($image);
The directory structure is something like this:
- root
- js
- css
- font
- img
Where php script is in the root folder and font files are in font folder.
The code above works on my local PC but does not work when i deploy to the server as imagettftext can't find the font and a error message is raised. Using URL full path does not work neither as imagettftext needs a local file path.
I've tried $font = '/font/Allerta-Regular.ttf' (without the initial dot) also but no luck.
I know that i can use "Google Cloud Storage" service but i don't want to hire it and duplicate files as this fonts are used from my js files also.
How can i specify the font in PHP app engine to use with imagettftext?
Thanks