9

この問題に対する答えをまだ探しているのは長い時間です..私が見つけたすべての解決策は、フォント名をキャッチすることですが、これは私の問題ではないと確信しています.

GDがインストールされているようです

array(11) {
  ["GD Version"]=>
  string(27) "bundled (**2.0.34 compatible**)"
  ["FreeType Support"]=>
  bool(false)
  ["T1Lib Support"]=>
  bool(false)
  ["GIF Read Support"]=>
  bool(true)
  ["GIF Create Support"]=>
  bool(true)
  ["JPEG Support"]=>
  bool(true)
  ["PNG Support"]=>
  bool(true)
  ["WBMP Support"]=>
  bool(true)
  ["XPM Support"]=>
  bool(true)
  ["XBM Support"]=>
  bool(true)
  ["JIS-mapped Japanese Font Support"]=>
  bool(false)
}

上に私の GD サポートが表示されます。PHP のバージョンは 5.3 で、Linux で実行しています。

さまざまな Web サイトからいくつかの異なるコード例を試しましたが、どれも機能しません。ImageString は機能しますが、imagettftextを機能させる必要があります。

これは私が今試した最後のコードです-

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

// Set the content-type
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 100) or die("Can't create image!");

// 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 own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, 'arial.ttf', $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, 'arial.ttf', $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

結果: http://www.7679679.com/app/test-ansi.php

4

5 に答える 5

20

同じ問題があり、FreeTypeがインストールされている場合、解決策は

 $font = "./Arial.ttf"; // <--- put ./ in front of filename
于 2013-02-21T11:52:00.777 に答える
8

Free Type がインストールされていないことに注意してください。

["FreeType Support"]=>
  bool(false)

この関数には、GD ライブラリと » FreeType ライブラリの両方が必要です。

この機能を使用するには、Free Type ライブラリをインストールする必要があります。

これらのパッケージをインストールしてみてください:s freetype, freetype-devel

PHP をコンパイルした場合は、コンパイル時に有効な freetype を追加したことを確認できます。

--with-freetype-dir=/usr/include/freetype2/ --with-freetype

または、YUM や APT-GET などを使用している場合は、これらのライブラリをインストールするのは非常に簡単で、Google ですばやく検索するだけで開始できます。

于 2013-02-21T10:40:41.457 に答える
8

まあ、私も問題を抱えています

$font='arial.tff'; 

$fontのように絶対パスを指定する必要があると思います

$font="c:/windows/fonts/arial.ttf";

あなたはWindowsユーザーだと思います。そして取り除く

header('Content-Type:image/png');

実際のエラーを取得するには

于 2015-03-15T07:22:30.087 に答える
4

このソリューションでこの問題を解決しました:

$fontfile= __DIR__.'/Fontname.ttf';
于 2019-06-12T14:20:54.193 に答える
-1

Andrewの言う通りです。ほとんどの人は GD devel パッケージで FreeType を自動的にインストールします:imagettftextimagettfbox

フェドーラ/レッドハット:

yum install gd gd-devel php-gd

Debian/Ubuntu:

apt-get install php5-gd libgd2-xpm libgd2-xpm-dev

このエラーはおそらくログに記録されていました:

PHP Fatal error:  Call to undefined function imageTTFText()
于 2014-11-03T10:14:21.840 に答える