テキストを入力してイメージに変換しようとしています。フォントのパスとは何ですか?
私はPHPマニュアルからいくつかのコードを得ました。 symfonyの3.1
でそれに取り組んで
イム私が持っている唯一の問題は、フォントのパスを設定しない方法です。
robot-regular.ttfは私の/webディレクトリにあります。
マイコード:
//setting the content type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400,30);
// 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 = 'Testing';
// Replace path by your font path
$font = 'Roboto-Regular.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() resulst in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);