これは、画像を作成するためにたどっているリンクですが、最初の例でテストしたように、私の GD はインストールされ、正しく動作していますが、このコードは壊れており、「エラーが含まれているため画像を表示できません」というフラグが立てられます。
コード-
<?php
//phpinfo();
//Report any errors
ini_set("display_errors", "1");
error_reporting(E_ALL);
//Set the content type
header('content-type: image/png');
//Create our basic image stream 300x300 pixels
$image = imagecreate(300, 300);
//$image = imagecreatetruecolor(300, 300);
//Set up some colors, use a dark gray as the background color
$dark_grey = imagecolorallocate($image, 102, 102, 102);
$white = imagecolorallocate($image, 255, 255, 255);
//Set the path to our true type font
//$font_path = 'advent_light';
//$font_path = 'advent_light.ttf';
//$font_path = 'arial';
$font_path = 'arial.ttf';
//Set our text string
$string = 'Swapnesh!';
//Write our text to the existing image.
imagettftext($image, 50, 0, 10, 160, $white, $font_path, $string);
//Create our final image
imagepng($image);
//Clear up memory
imagedestroy($image);
?>
私が試してググったが解決策がないことは次のとおりです-:(
- php タグの前に空白スペースがある場合は、それをチェックしました。
- header()メソッドの前にあるすべてのコードとスペースを削除します。
- コード内のコメントのように、 imagecreate ()をimagecreatetruecolor( ) に変更しました。
- font_path を確認し、コメントに従ってフォントパスを設定しました。
- これとこれをフォローしました。
私の PHP バージョン - PHP バージョン 5.3.8
まだ問題を特定できません:(
エラー
編集-
バージョン 1.0
これは私が節約しているものです。
画像に関する詳細情報 --
ページの保存時 -- これはファイル保存の名前です -- create_png.php.png
バージョン 1.1
<br />
<b>Warning</b>: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in <b>C:\xampp\htdocs\Core\CoreFiles\create_png.php</b> on line <b>20</b><br />
<br />
<b>Warning</b>: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in <b>C:\xampp\htdocs\Core\CoreFiles\create_png.php</b> on line <b>23</b><br />
とのおかげ@cryptic
で@user1711126
解決策--
フォント ファイルが実際にはありません。.ttf ファイルをフォルダーの下に配置して、このコードを機能させるか、パスを設定して機能させる必要があります。