[PHP-users 1907] Re: PHP4.0.6+gd+freetypeで imgttftext がエラーに

KK.Kon php-users@php.gr.jp
Fri, 7 Sep 2001 14:06:36 +0900


 ども、KK.Konです。

 gdのTTFがらみということですが、私もはまりました。
 エラーメッセージは 'No TTF support in this PHP build' だと思います。

 原因はgdのバージョンに起因します。
 gd-1.8.3 は freetype-1(freetype-1.3.1.tar.gzなど)
 gd-1.8.4 は freetype-2(freetype-2.0.4.tar.bz2など)

http://www.boutell.com/gd/manual1.8.4.html

 アプローチとしては2つあります。
 1.php-4.0.6側を変更する(FreeType2でGDを作った場合)
 2.gd-1.8.4側を変更する

1.
 php-4.0.6側の変更であれば
 php-4.0.6/ext/gd/gd.c
 の2665行目にある
 #if の条件式の変更でOKです

# diff -Nr gd.c gd.c.orig
2665c2665
< # if HAVE_LIBGD20 | HAVE_LIBFREETYPE
---
> # if HAVE_LIBGD20 & HAVE_LIBFREETYPE

 php-4.0.6/main/php_config.h で
#define USE_GD_IMGSTRTTF 1
#define HAVE_LIBFREETYPE 1
/* #undef HAVE_LIBTTF */

 のようにLIBTTFではなくてLIBFREETYPEを使用するようになっていればOKです
 EXTRA_LIBS に -lgd -lfreetype となっていればコンパイルできます。

 私のところの phpinfo が吐く configure オプションですが、ソースの方をいじっ
て修正かけたので
 参考にならないと思います。

'./configure'
 '--with-apxs=/usr/local/sbin/apxs'
 '--with-config-file-path=/usr/local/etc'
 '--enable-versioning'
 '--with-system-regex'
 '--disable-debug' '--enable-track-vars'
 '--without-gd' '--without-mysql'
 '--with-gd=/usr/local' '--with-freetype-dir=/usr/local'
 '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local'
 '--enable-gd-native-ttf' '--with-zlib'
 '--with-mcrypt=/usr/local' '--with-mhash=/usr/local'
 '--with-pdflib=/usr/local' '--with-zlib-dir=/usr'
 '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local'
 '--with-tiff-dir=/usr/local' '--with-imap=/usr/local'
 '--with-pgsql=/usr/local' '--with-ldap=/usr/local'
 '--with-xml' '--with-expat-dir=/usr/local'
 '--with-sablot=/usr/local' '--with-expat-dir=/usr/local'
 '--enable-ftp' '--with-curl=/usr/local'
 '--with-gettext=/usr/local' '--with-iconv=/usr/local'
 '--with-pspell=/usr/local' '--enable-mbregex'
 '--enable-mbstring' '--enable-bcmath'
 '--with-hyperwave=yes' '--with-ming=/usr/local'
 '--enable-sockets' '--enable-sysvsem'
 '--enable-sysvshm' '--enable-trans-sid'
 '--with-iconv=/usr/local' '--prefix=/usr/local' 'i386--freebsd4.4'


2.
 は
http://ns1.php.gr.jp/pipermail/php-users/2001-July/000666.html

 の方法でほぼ正解だと思います。
 ただPHP-3のときの方法だと思います。


 根本的には
 php-4.0.6/ext/gd/gd.c の php_imagettftext_common 関数内の
 php-3.0.18/functions/gd.c の php3_imagettftext_common 関数内の

#if HAVE_GD_TTF
# if HAVE_LIBFREETYPE
        error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x,
y, string);
# else
        error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x,
y, string);
# endif
#else
        error = gdttf(im, brect, col, fontname, ptsize, angle, x, y,
string);
#endif

 等の部分でどのGDか判定しているだけです。

 gdttfを呼べば freetype1 を想定
 gdImageStringTTFを呼べば freetype2 を想定なので
 ソースに修正をかける場合はこの部分が重要となります。

P.S
 ああ、あと、freetype1 と freetype2 とでは出力されるフォントの大きさがぜん
ぜん違います。
 以前連れがGD-1.8.3とfreetype1でPHPからTTF入りの画像を出力していたのですが
 GD-1.8.4とfreetype2にしたところ、デザインが狂ってしまいました。