Usage

Default interface file file.drawtext2.php has basic drawing parameters, the list of which is shown below. Those parameters are to be set in the URL of the script file. For example:

デフォルトのインターフェイスファイル file.drawtext2.php にはいくつかのパラメータが用意されています(下部を参照)。パラメータはファイルへの URL に記述します。例えば、

<img src="file.drawtext2.php?text='PHP Font Image Generator 2' &amp;font='font/MyriadBold.ttf' &amp;size=20 &amp;color=0x000000 &amp;bgcolor=0xffffff" alt="" />

If you write that in the src attribute of an img tag, this will be:

これを img タグの src 属性に記述すれば、次のように表示されます。

You should always quote string value of parameter such as text or font by '' (single quotes) or "" (double quotes), so that it is not to be considered as a number value or constant value. The value of the font parameter is the path to your own True Type font file from the script file, not from the HTML file.

When you want to create a long text image with line breaks (\n), the code follows:

textfont などのパラメータの文字型の値は ''(シングル・クオート)か ""(ダブル・クオート)の中になければなりません。数字型や定数型との混同を防ぐためです。font パラメータの値は自分の True Type フォントへのファイルパスになります。これは HTML ファイルからのパスではなく、スクリプトファイルからのパスです。

改行(\n)を含むような長い文字列の画像を作りたいときは、次のように書きます。

<img src="file.drawtext2.php?text='&quot;We live in an age in which only results seem to count, not processes... But life is liquid, not solid; a process, not a result; the present, not the future.&quot; -- Keith Jarrett\n\n&quot;To have peace with this peculiar life; to accept what we do not understand; to wait calmly for what awaits us, you have to be wiser than I am.&quot; -- M.C.Escher' &amp;font='font/HelveticaNeueBold.ttf' &amp;size=7 &amp;leading=15 &amp;color=0x000000 &amp;alpha=80 &amp;bgcolor=0xffffff &amp;width=300 &amp;align=center-adjust" alt="" />

this will be:

このコードは次のように表示されます。

Those are the most simple way of drawings. If you want to make much complicated image, use the exec parameter. For example, with the use of a Javascript file class.rollovercontroller2.js:

これらは一番簡単な描画方法で、もっと複雑な内容を含んだ画像を作りたいときは exec パラメータを用います。次の例では Javascript ファイル class.rollovercontroller2.js を一緒に用いています。

<img src="file.drawtext2.php?exec=autoresize both; color {bgcolor}; fill; image {leftCap},0,0; translate {leftCap.width},0; patternrect {fill},0,0,{width},20; image {rightCap},{width},0; font 'font/MyriadSemibold.ttf',8.5,8.5; color 0,0,0,50; string {text},0,5,{width},center; color 0xffffff; string {text},0,4,{width},center; &amp;leftCap={image: 'img/ButtonLeftInactive.png'} &amp;fill={image: 'img/ButtonFillInactive.png'} &amp;rightCap={image: 'img/ButtonRightInactive.png'} &amp;bgcolor={color: 0x555555} &amp;text='Trot, Canter, Gallop' &amp;width=110" alt="" onload="RCLoad(this, {hover:['Inactive','Active','Inactive','Active','Inactive','Active']});" onmouseover="RCActivate(this,'hover');" onmouseout="RCInactivate(this);" />

this will be:

これは次のようになります。

Once you wrote a code like that, some changes only in some parameters enable it to fit anywhere, any context.

Additionally, you can easily make the replacement of file.drawtext2.php by inheriting GMIPluggableSet class so that you don't have to write that long code every time but some parameters on it. The file.drawbutton.php, for example, only text and width parameters are required.

このようなコードを一度作れば、幾つかのパラメータを変更するだけで、どんな場所でもどんな文脈にも合う画像を作れます。

さらに、GMIPluggableSet クラスを継承して file.drawtext2.php の代替ファイルを作れば、毎回このような長いコードを書く必要も無くなり、単にパラメータを書くだけで済むようになります。以下の例では file.drawbutton.php ファイルを作り、textwidth パラメータのみを書いています。

<img src="file.drawbutton.php?text="Trot, Canter, Gallop' &amp;width=110" alt="" />

This will result the same as the image above.

See also Reference page for much information of the syntax, functions and variables of code in the exec parameter.

これは上の画像と同じ結果になります。

exec パラメータに書くコードの文法や関数、変数などについては リファレンス・ページ をご覧ください。

Parameter List

Name Type Description Default value
text string text to draw  
font string name of the font file  
size number size of the font  
color number color of the text 0x000000
alpha number alpha value of the text 100
leading number leading of the font {size}
padding number extra spaces around image 0
width number width of the text box  
height number height of the text box.  
align constant horizontal alignment of the text
[left | center | right | left-adjust | center-adjust | right-adjust | adjust]
left
valign constant vertical alignment of the text
[top | middle | bottom]
middle
bgcolor number color of the background 0xffffff
bgtrans boolean whether background color is transparent  
bgimage string name of the pattern image  
antialias number quality of the text antialias 4
type constant type of the image file to output
[gif | png | jpeg]
gif
file string path of the image file to create  
palette number the number of colors in the gif or png image file to output 256
quality number the quality of the jpeg image file to output 100
exec   execution expressions, see Reference page for more detail.  
名前 説明 デフォルト値
text string 描画する文字列  
font string フォントファイルのパス  
size number フォントサイズ  
color number 文字列の色 0x000000
alpha number 文字列の透明度 100
leading number 文字列の行間 {size}
padding number 画像周辺の余白 0
width number テキストボックスの幅  
height number テキストボックスの高さ  
align constant 水平方向の文字整列
[left | center | right | left-adjust | center-adjust | right-adjust | adjust]
left
valign constant 垂直方向の文字整列
[top | middle | bottom]
middle
bgcolor number 背景色 0xffffff
bgtrans boolean 背景を透明にするかどうか  
bgimage string パターン画像のパス  
antialias number 文字列のアンチエイリアスの質 4
type constant 出力するファイルタイプ
[gif | png | jpeg]
gif
file string 作成する画像ファイルのパス  
palette number GIF か PNG での色数 256
quality number JPEG での圧縮率 100
exec   実行コード。詳しくは リファレンス・ページ をご覧ください  

Thank you for your wonderful work.

2006-10-22 01:59:08 JST
Roger Baumann

First of all thank you for a wonderful script! second, I was wondering, I get some fonts which seem to be cutting off, either at the top or the bottom. any way to fix this?

Thanks,
Ran

2007-04-06 08:58:46 JST
Ran Baron

Some people actually reported this rendering problem of accented uppercase glyphs, and my conclusion is that Fig2 cannot handle every glyph in font file correctly. A quick solution is to change the file "package.adt.php" at the line 171:

$this->cornersCache = $this->_calcurateCorners("ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz1234567890");

This line stores minimum dimension of major glyphs from A to Z, a to z, 0 to 9, so please add a larger glyph, Ú, for example:

$this->cornersCache = $this->_calcurateCorners("ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz1234567890Ú");

Because php does not have any function to get metrics information from font file, fig2 measures glyphs within the dimension of a rendered image out of imagettftext function.
However, as you noticed, this has a quite large limitation because we cannot put all the glyphs in font file.

2007-04-06 09:08:47 JST
Matsuda Shota

Thank you sooooooo much! that did the trick! I'm using Sanskrit and Hindi scripts, which are unusually high.
Ran

2007-04-06 17:02:08 JST
Ran Baron

ok.. i just put in an html file and the pic is black and 200x200 coz i put width="200" in there.. otherwise it's a black pixel.

my font file is in the fig2 folder.. my computer meets the requirements. no errors, no nothing.. so.. why won't it work? :(

2007-08-17 01:36:19 JST
do

Hi,
Greeat script.
Is there a way to get the image size of the generated file? I tried getimagesize() but it wont work.
Thanks,
John

2007-08-19 00:49:33 JST
John

Hey i sent you a mail from this email address - could you please help me?
thanks

2007-11-21 03:26:10 JST
Andreas

i've some problem with php 5 and gd lib 2.
when i put some aligned text and i try to underline it with the StringWidth() there a many differens between font and underline. if put some textlines e.g. "a" "aaaaaa" and "aaaaaaaaaa" then u can see the error clearly...
with gd lib 1.4 it works fine. so what is happen?

thanks 4 answer

2008-02-19 04:49:11 JST
Tobi

Hi
I am trying to convert a hindi script into image, but half characters are displayed fully. Can you suggest how this can be done.
Below is the url kindly check it out, the images are showing the wrong data, whereas the unicode is the correct data
http://www.indiainfo.com/abc1.html

2008-03-25 19:21:49 JST
Arokia Nathan
Toggle Comment Form