=begin comment $Id: GD-jp.pod,v 1.12 2006-01-06 18:29:56+09 shige Exp $ GD-jp.pod 日本語訳: Shigeharu TAKENO 1) % perldoc -u GD.pm > GD.pod としたものの日本語訳。現在は GD.pm version 2.28 の訳。 2) 原文は begin comment 〜 end comment 内に残しているものもあれば、そうで ないものもある。 3) .pod ファイルとして利用する場合は、=begin comment 〜 =end comment 部分 を削除してから利用すること。例えば以下の通り: % sed '/^=begin comment/,/^=end comment/'d GD-jp.pod | pod2text \ > GD-jp.txt 4) pod2text で変換すると行末が合わないよう。こちらでそう書いておく必要があ るみたい。pod2man | nroff -man も、あまり綺麗ではない。 5) 訳に関しては、shige@iee.niit.ac.jp に連絡すること。 7) ライセンスは、元のファイルのライセンスと同様とする。詳しくは、 「著者」の節を参照。 =end comment =head1 名前 GD.pm - GD library に対するインターフェース =head1 形式 use GD; # 新しい画像を作成 $im = new GD::Image(100,100); # 色をいくつか割り当て $white = $im->colorAllocate(255,255,255); $black = $im->colorAllocate(0,0,0); $red = $im->colorAllocate(255,0,0); $blue = $im->colorAllocate(0,0,255); # 背景を透明にしてインターレース画像にする $im->transparent($white); $im->interlaced('true'); # 絵のまわりに黒枠をつける $im->rectangle(0,0,99,99,$black); # 青の楕円を描画 $im->arc(50,50,95,75,0,360,$blue); # そしてそれを赤で塗りつぶす $im->fill(50,50,$red); # バイナリ出力することを確認 binmode STDOUT; # 画像を PNG にしてそれを標準出力へ出力 print $im->png; =head1 機能説明 =begin comment B is a Perl interface to Thomas Boutell's gd graphics library (version 2.01 or higher; see below). GD allows you to create color drawings using a large number of graphics primitives, and emit the drawings as PNG files. =end comment B は、Thomas Boutell の gd グラフィックライブラリ (version 2.01 以降; 以下を参照) への Perl インターフェースの一つです。 GD によって、たくさんのグラフィック基本命令を使ってカラー画像を作れますし、 それを PNG ファイルとして出力もできます。 =begin comment GD defines the following three classes: =end comment GD は以下の 3 つのクラスを定義しています: =over 5 =item C =begin comment An image class, which holds the image data and accepts graphic primitive method calls. =end comment これはイメージクラスで、画像データを保持しグラフィックの 基本メソッド呼び出しを受けつけます。 =item C =begin comment A font class, which holds static font information and used for text rendering. =end comment これはフォントクラスで、静的なフォント情報を保持し、 文字の画像化に使われます。 =item C =begin comment A simple polygon object, used for storing lists of vertices prior to rendering a polygon into an image. =end comment これは単なる多角形オブジェクトで、 ある画像内に多角形を描画する前に各頂点のリストを保存するのに 使われます。 =back 簡単な例: #!/usr/local/bin/perl use GD; # 新しい画像を作成 $im = new GD::Image(100,100); # 色をいくつか割り当て $white = $im->colorAllocate(255,255,255); $black = $im->colorAllocate(0,0,0); $red = $im->colorAllocate(255,0,0); $blue = $im->colorAllocate(0,0,255); # 背景を透明にしてインターレース画像にする $im->transparent($white); $im->interlaced('true'); # 絵のまわりに黒枠をつける $im->rectangle(0,0,99,99,$black); # 青の楕円を描画 $im->arc(50,50,95,75,0,360,$blue); # そしてそれを赤で塗りつぶす $im->fill(50,50,$red); # バイナリ出力することを確認 binmode STDOUT; # 画像を PNG にしてそれを標準出力へ出力 print $im->png; 注意: =over 5 =item 1. =begin comment To create a new, empty image, send a new() message to GD::Image, passing it the width and height of the image you want to create. An image object will be returned. Other class methods allow you to initialize an image from a preexisting JPG, PNG, GD, GD2 or XBM file. =end comment 新しい、空の画像を作成するには、作成したい画像の横幅と高さを渡して new() メッセージを GD::Image に送ります。 すると画像のオブジェクトが返されます。 他のクラスメソッドによって、既に存在する JPG, PNG, GD, GD2, XBM ファイルから画像を初期化することもできます。 =item 2. =begin comment Next you will ordinarily add colors to the image's color table. colors are added using a colorAllocate() method call. The three parameters in each call are the red, green and blue (rgb) triples for the desired color. The method returns the index of that color in the image's color table. You should store these indexes for later use. =end comment 次は普通は画像のカラー表に色を追加します。 色は colorAllocate() メソッド呼び出しで追加します。 その各呼び出しの 3 つの引数は、その色の赤/緑/青 (rgb) の 3 つの成分です。 そのメソッドはカラー表内のその色の番号を返します。 後で使うために、その番号を保存しておかなければなりません。 =item 3. =begin comment Now you can do some drawing! The various graphics primitives are described below. In this example, we do some text drawing, create an oval, and create and draw a polygon. =end comment これで任意の描画が可能です。 様々なグラフィックス基本命令を使うことができ、 それらは以下で紹介します。 例えば、文字列の描画、楕円の生成、多角形描画などが行えます。 =item 4. =begin comment Polygons are created with a new() message to GD::Polygon. You can add points to the returned polygon one at a time using the addPt() method. The polygon can then be passed to an image for rendering. =end comment 多角形は new() メッセージによって GD::Polygon に生成されます。 それにより返される多角形オブジェクトに、 addPt() メソッドを使うことで点を追加することも可能です。 その後その多角形を描画のために画像に渡すことができます。 =item 5. =begin comment When you're done drawing, you can convert the image into PNG format by sending it a png() message. It will return a (potentially large) scalar value containing the binary data for the image. Ordinarily you will print it out at this point or write it to a file. To ensure portability to platforms that differentiate between text and binary files, be sure to call C on the file you are writing the image to. =end comment 描画が終わったら、png() メッセージを送ることで PNG 形式の画像に変換できます。 これは、画像のバイナリデータを含む (かなり大きな) スカラー値を返します。 通常、この時にそれを print するかファイルに書き出します。 テキストファイルとバイナリファイルに関してプラットホーム間の互換性を取るため、 画像を書き出すファイルには C を使ってください。 =back =head1 オブジェクトの生成関数: 画像の生成 =begin comment The following class methods allow you to create new GD::Image objects. =end comment 以下のクラスメソッドで、新しい GD::Image オブジェクトを作成できます。 =over 4 =item B<$image = GD::Image-Enew([$width,$height],[$truecolor])> =item B<$image = GD::Image-Enew(*FILEHANDLE)> =item B<$image = GD::Image-Enew($filename)> =item B<$image = GD::Image-Enew($data)> =begin comment The new() method is the main constructor for the GD::Image class. Called with two integer arguments, it creates a new blank image of the specified width and height. For example: =end comment メソッド new() は GD::Image クラスの中心的な生成関数です。 整数引数 2 つで呼び出した場合は、 その横幅と縦幅を持つ新しい空の画像を生成します。 例: $myImage = new GD::Image(100,100) || die; =begin comment This will create an image that is 100 x 100 pixels wide. If you don't specify the dimensions, a default of 64 x 64 will be chosen. =end comment これは 100 x 100 ピクセルの大きさの画像を生成します。 大きさを指定しなかった場合、デフォルトでは 64 x 64 が選択されます。 =begin comment The optional third argument, $truecolor, tells new() to create a truecolor GD::Image object. Truecolor images have 24 bits of color data (eight bits each in the red, green and blue channels respectively), allowing for precise photograph-quality color usage. If not specified, the image will use an 8-bit palette for compatibility with older versions of libgd. =end comment オプションの 3 番目の引数 $truecolor は、new() に truecolor の GD::Image オブジェクトを生成させます。truecolor イメージは 24 ビットの色データ (R/G/B それぞれに 8 ビット) を持ち、 鮮明な写真並の色の画質を与えます。 これを指定しなかった場合は、古い版の libgd との互換性のために、 画像は 8 ビットのパレットを使います。 =begin comment Alternatively, you may create a GD::Image object based on an existing image by providing an open filehandle, a filename, or the image data itself. The image formats automatically recognized and accepted are: PNG, JPEG, XPM and GD2. Other formats, including WBMP, and GD version 1, cannot be recognized automatically at this time. =end comment また、GD::Image オブジェクトを、 ファイルハンドル、ファイル名、または画像データそれ自身を与えることで、 既に存在する画像を元に生成することも可能です。 次の画像フォーマットは自動的に認識されます: PNG, JPEG, XPM, GD2。 例えば WBMP や version 1 の GD などのそれ以外のフォーマットの場合、 現在は自動的に認識させることはできません。 =begin comment If something goes wrong (e.g. insufficient memory), this call will return undef. =end comment 何か問題があった場合 (例えばメモリが足りない)、この呼び出しは undef を返します。 =item B<$image = GD::Image-EtrueColor([0,1])> =begin comment For backwards compatibility with scripts previous versions of GD, new images created from scratch (width, height) are palette based by default. To change this default to create true color images use: =end comment 以前の版の GD 用のスクリプトへの互換性のために、 (width, height) だけから生成される新しい画像は、 デフォルトではパレットベースになります。 truecolor 画像を作成するためにこのデフォルトを変えるには以下の行: GD::Image->trueColor(1); =begin comment somewhere before creating new images. To switch back to palette based by default, use: =end comment を、新しい画像を生成する前のどこかに入れてください。 デフォルトのパレットベースに戻すには、以下のようにします: GD::Image->trueColor(0); =item B<$image = GD::Image-EnewPalette([$width,$height])> =item B<$image = GD::Image-EnewTrueColor([$width,$height])> =begin comment The newPalette() and newTrueColor() methods can be used to explicitly create an palette based or true color image regardless of the current setting of trueColor(). =end comment newPalette() と newTrueColor() メソッドは、 現在の trueColor() の設定を考えることなく、 パレットベースか truecolor 画像にするのかを明示的に指定するのに使えます。 =item B<$image = GD::Image-EnewFromPng($file, [$truecolor])> =item B<$image = GD::Image-EnewFromPngData($data, [$truecolor])> =begin comment The newFromPng() method will create an image from a PNG file read in through the provided filehandle or file path. The filehandle must previously have been opened on a valid PNG file or pipe. If successful, this call will return an initialized image which you can then manipulate as you please. If it fails, which usually happens if the thing at the other end of the filehandle is not a valid PNG file, the call returns undef. Notice that the call doesn't automatically close the filehandle for you. But it does call C for you, on platforms where this matters. =end comment メソッド newFromPng() は、PNG ファイルを指定されたファイルハンドルか ファイルのパスから読み込んで画像を生成します。 ファイルハンドルは、存在する PNG ファイルかパイプをあらかじめ開いたもの である必要があります。 成功した場合、このメソッドは初期化された画像を返し、 それを好きなように操作できます。 失敗した場合、例えばファイルハンドルの反対側が正しい PNG ファイルでない 場合などでよく起こりますが、この場合これは undef を返します。 この呼び出しは、自動的にファイルハンドルを閉じたりはしないことに 注意してください。 しかし、C は、それが問題となるようなプラットホームでは 呼び出されます。 =begin comment You may use any of the following as the argument: 1) a simple filehandle, such as STDIN 2) a filehandle glob, such as *PNG 3) a reference to a glob, such as \*PNG 4) an IO::Handle object 5) the pathname of a file In the latter case, newFromPng() will attempt to open the file for you and read the PNG information from it. =end comment 引数は、次のいずれかを使うことができます。 1) STDIN 等の、単なるファイルハンドル 2) *PNG 等の、ファイルハンドルのグロブ 3) \*PNG 等の、グロブへの参照 4) IO::Handle オブジェクト 5) ファイルのパス名 =begin comment In the latter case, newFromPng() will attempt to open the file for you and read the PNG information from it. =end comment 一番最後の場合は、newFromPng() はそのファイルをオープンし、 そこから PNG 情報を読み出します。 例 1: open (PNG,"barnswallow.png") || die; $myImage = newFromPng GD::Image(\*PNG) || die; close PNG; 例 2: $myImage = newFromPng GD::Image('barnswallow.png'); =begin comment To get information about the size and color usage of the information, you can call the image query methods described below. Images created by reading PNG images will be truecolor if the image file itself is truecolor. To force the image to be palette-based, pass a value of 0 in the optional $truecolor argument. =end comment 大きさや色の使用に関する情報を取得するために、 以下に記述する画像要求メソッドを使うことができます。 PNG 画像を読み込んで生成された画像は、 それ自身が truecolor の場合 truecolor になります。 画像を強制的にパレットベースにするには、 0 という値をオプション引数 $truecolor に渡してください。 =begin comment The newFromPngData() method will create a new GD::Image initialized with the PNG format B contained in C<$data>. =end comment メソッド newFromPngData() は、C<$data> に含まれる PNG 形式の B<データ> で初期化された新しい GD::Image を生成します。 =item B<$image = GD::Image-EnewFromJpeg($file, [$truecolor])> =item B<$image = GD::Image-EnewFromJpegData($data, [$truecolor])> =begin comment These methods will create an image from a JPEG file. They work just like newFromPng() and newFromPngData(), and will accept the same filehandle and pathname arguments. =end comment これらのメソッドは JPEG ファイルから画像を生成します。 これらは丁度 newFromPng() と newFromPngData() と同様に動作し、 同じファイルハンドルやパス名の引数を受け付けます。 =begin comment Images created by reading JPEG images will always be truecolor. To force the image to be palette-based, pass a value of 0 in the optional $truecolor argument. =end comment JPEG 画像を読み込むことで生成される画像は常に truecolor になります。 画像を強制的にパレットベースにするには、 0 という値をオプション引数 $truecolor に渡してください。 =item B<$image = GD::Image-EnewFromGif($file)> =item B<$image = GD::Image-EnewFromGif($data)> =begin comment These methods will create an image from a GIF file. They work just like newFromPng() and newFromPngData(), and will accept the same filehandle and pathname arguments. =end comment これらのメソッドは GIF ファイルから画像を生成します。 これらは丁度 newFromPng() と newFromPngData() と同様に動作し、 同じファイルハンドルやパス名の引数を受け付けます。 =begin comment Images created from GIFs are always 8-bit palette images. To convert to truecolor, you must create a truecolor image and then perform a copy. =end comment GIF 画像から生成される画像は常に 8 ビットパレットカラーになります。 これを truecolor に変換するには、 一つ truecolor 画像を生成し、そしてコピーを行う必要があります。 =item B<$image = GD::Image-EnewFromXbm($file)> =begin comment This works in exactly the same way as C, but reads the contents of an X Bitmap (black & white) file: =end comment これは C と同様に動作しますが、X ビットマップ (白黒) ファイルの内容を読み込みます: open (XBM,"coredump.xbm") || die; $myImage = newFromXbm GD::Image(\*XBM) || die; close XBM; =begin comment There is no newFromXbmData() function, because there is no corresponding function in the gd library. =end comment gd ライブラリに対応する関数がありませんので、 newFromXbmData() という関数はありません。 =item B<$image = GD::Image-EnewFromGd($file)> =item B<$image = GD::Image-EnewFromGdData($data)> =begin comment These methods initialize a GD::Image from a Gd file, filehandle, or data. Gd is Tom Boutell's disk-based storage format, intended for the rare case when you need to read and write the image to disk quickly. It's not intended for regular use, because, unlike PNG or JPEG, no image compression is performed and these files can become B. =end comment これらのメソッドは GD::Image を Gd ファイル、ファイルハンドル、データ などから初期化します。Gd は Tom Boutell のディスクベースの保存形式で、 画像とディスクの間の読み書きを速くしたいというごく稀な場合向きで、 通常の使用向きではありません。それは、PNG や JPEG とは異なり 画像圧縮を行わず、ファイルサイズが B<大きく> なる可能性があります。 $myImage = newFromGd GD::Image("godzilla.gd") || die; close GDF; =item B<$image = GD::Image-EnewFromGd2($file)> =item B<$image = GD::Image-EnewFromGd2Data($data)> =begin comment This works in exactly the same way as C and newFromGdData, but use the new compressed GD2 image format. =end comment これは C, newFromGdData と全く同様に動作しますが、 新しい圧縮 GD2 画像形式を使用します。 =item B<$image = GD::Image-EnewFromGd2Part($file,srcX,srcY,width,height)> =begin comment This class method allows you to read in just a portion of a GD2 image file. In additionto a filehandle, it accepts the top-left corner and dimensions (width,height) of the region of the image to read. For example: =end comment このクラスメソッドで GD2 画像の一部分を読み出すことができます。 ファイルハンドルに加えて、 切り出す領域の左上の角の位置とその大きさ (width,height) を与えます。 例: open (GDF,"godzilla.gd2") || die; $myImage = GD::Image->newFromGd2Part(\*GDF,10,20,100,100) || die; close GDF; =begin comment This reads a 100x100 square portion of the image starting from position (10,20). =end comment これは、(10,20) から始まる 100x100 の正方形の部分を読み込みます。 =item B<$image = GD::Image-EnewFromXpm($filename)> =begin comment This creates a new GD::Image object starting from a B. This is unlike the other newFrom() functions because it does not take a filehandle. This difference comes from an inconsistency in the underlying gd library. =end comment これは B のファイルから新しい GD::Image オブジェクトを生成します。 これは他の newFrom() 関数とは違っていて、 ファイルハンドルを引数には取りません。 この違いは、本となる gd ライブラリに含まれる矛盾によります。 $myImage = newFromXpm GD::Image('earth.xpm') || die; =begin comment This function is only available if libgd was compiled with XPM support. =end comment この関数は、libgd が XPM をサポートする形でコンパイルされている場合にのみ 有効です。 =begin comment NOTE: The libgd library is unable to read certain XPM files, returning an all-black image instead. =end comment 注意: libgd ライブラリはある特定の XPM ファイルを読み込むことができず、 その場合全部黒の画像を返します。 =head1 GD::Image メソッド =begin comment Once a GD::Image object is created, you can draw with it, copy it, and merge two images. When you are finished manipulating the object, you can convert it into a standard image file format to output or save to a file. =end comment GD::Image が一度生成されると、そこに描画したり、それをコピーしたり、 2 つの画像を結合したりできます。 オブジェクトに対する操作が終了したら、 それを出力したりファイルに保存したりするために 標準的な画像形式に変換することができます。 =head2 画像データ出力メソッド =begin comment The following methods convert the internal drawing format into standard output file formats. =end comment 以下のメソッドは内部の画像形式を標準的なファイル形式に変換します。 =item B<$pngdata = $image-Epng([$compression_level])> =begin comment This returns the image data in PNG format. You can then print it, pipe it to a display program, or write it to a file. Example: =end comment これは PNG 形式の画像データを返します。それを print したり、 画像表示プログラムへパイプで渡したり、ファイルに書き出したりできます。 例: $png_data = $myImage->png; open (DISPLAY,"| display -") || die; binmode DISPLAY; print DISPLAY $png_data; close DISPLAY; =begin comment Note the use of C. This is crucial for portability to DOSish platforms. =end comment C の使用に注意してください。 これは DOS 等のプラットホームとの互換性を取るためには必要です。 =begin comment The optional $compression_level argument controls the amount of compression to apply to the output PNG image. Values range from 0-9, where 0 means no compression (largest files, highest quality) and 9 means maximum compression (smallest files, worst quality). A compression level of -1 uses the default compression level selected when zlib was compiled on your system, and is the same as calling png() with no argument. Be careful not to confuse this argument with the jpeg() quality argument, which ranges from 0-100 and has the opposite meaning from compression (higher numbers give higher quality). =end comment オプション引数の $compression_level は、 出力の PNG 画像に適用する圧縮のレベルを制御します。 値は 0-9 の範囲で、0 は圧縮なし (サイズは最大、画質は最高) で 9 は最も強い圧縮 (サイズは最小、画質は最低) を意味します。 圧縮レベルを -1 にすると、 zlib がシステムにインストールされている場合には デフォルトの圧縮レベルが選択されますが、 これは png() を引数なしで呼び出したときと同じになります。 この引数を jpeg() の画質の引数と混乱しないように注意してください。 jpeg() の画質の方は 0-100 の範囲で、圧縮とは逆の意味になっています (大きい数字が画質がいい)。 =item B<$gifdata = $image-Egifanimbegin([$GlobalCM [, $Loops]])> =begin comment For libgd version 2.0.33 and higher, this call begins an animated GIF by returning the data that comprises animated gif image file header. After you call this method, call gifanimadd() one or more times to add the frames of the image. Then call gifanimend(). Each frame must be the same width and height. =end comment libgd の version 2.0.33 以上では、 この呼び出しはアニメーション GIF を開始し、 アニメーション GIF ファイルヘッダを含むデータを返します。 このメソッドの呼び出しの後で、画像フレームを gifanimadd() を呼び出す (1 回、または複数回) ことで追加します。 そして gifanimend() を呼び出します。 各フレームは同じ横幅と同じ高さでなければいけません。 =begin comment A typical sequence will look like this: =end comment 作業の流れは例えば以下のようになります: my $gifdata = $image->gifanimbegin; $gifdata .= $image->gifanimadd; # 最初のフレーム for (1..100) { # 同じサイズのフレームを生成 my $frame = GD::Image->new($image->getBounds); add_frame_data($frame); # このフレームにデータを追加 $gifdata .= $frame->gifanimadd; # フレームの追加 } $gifdata .= $image->gifanimend; # アニメーション GIF 終了 print $gifdata; # STDOUT にアニメーション GIF を出力 =begin comment If you do not wish to to store the data in memory, you can print it to stdout or a file. =end comment メモリにデータを保存しておきたくない場合は、 それを標準出力かファイルに print できます。 =begin comment The image that you call gifanimbegin on is used to set the image size, color resolution and color map. If argument $GlobalCM is 1, the image color map becomes the GIF89a global color map. If $Loops is given and >= 0, the NETSCAPE2.0 application extension is created, with looping count. Looping count 0 means forever. =end comment gifanimbegin を呼び出した画像は、画像のサイズ、色の解像度、 色の割り当てを設定するのに使用されます。 引数 $GlobalCM を 1 とすると、画像の色の割り当ては GIF89a のグローバル カラーマップになります。 $Loops に 0 以上の値を指定した場合、 そのループ回数の NETSCAPE2.0 拡張で作成されます。 ループ回数 = 0 は無限ループを意味します。 =item B<$gifdata = $image-Egifanimadd([$LocalCM [, $LeftOfs [, $TopOfs [, $Delay [, $Disposal [, $previm]]]]]])> =begin comment Returns the data that comprises one animated gif image frame. You can then print it, pipe it to a display program, or write it to a file. With $LeftOfs and $TopOfs you can place this frame in different offset than (0,0) inside the image screen. Delay between the previous frame and this frame is in 1/100s units. Disposal is usually and by default 1. Compression is activated by giving the previous image as a parameter. This function then compares the images and only writes the changed pixels to the new frame in animation. The Disposal parameter for optimized animations must be set to 1, also for the first frame. $LeftOfs and $TopOfs parameters are ignored for optimized frames. =end comment これは一つのアニメーション GIF 画像フレームを含むデータを返します。 それを print したり、表示プログラムにパイプ経由で渡したり、 ファイルに書き出したりできます。 引数 $LeftOfs と $TopOfs は、このフレームを画像のスクリーン内の (0,0) 以外の場所に置く場合に使用します。 前のフレームと現在のフレームとの間隔 $Delay は 1/100 秒単位の指定です。 $Disposal は通常、そしてデフォルトでは 1 になっています。 圧縮は、直前の画像をパラメータとして与えることで有効になります。 この関数はその 2 枚の画像を比較し、変更されたピクセルのみを アニメーションの新しいフレームに書き出します。 アニメーションの最適化のためには $Disposal パラメータは 1 にセットすべきで、 最初のフレームに関するものにもなっています。 $LeftOfs, $TopOfs は最適化フレームに関しては無視されます。 =item B<$gifdata = $image-Egifanimend()> =begin comment Returns the data for end segment of animated gif file. It always returns string ';'. This string must be printed to an animated gif file after all image frames to properly terminate it according to GIF file syntax. Image object is not used at all in this method. =end comment これはアニメーション GIF ファイルの最後の部分のデータを返します。 これは常に文字列 ';' を返します。 この文字列は、アニメーション GIF ファイルの書式に従って、 アニメーション GIF ファイルの全ての画像フレームの後に出力すべきものです。 このメソッドでは画像オブジェクトは一切使われません。 =item B<$jpegdata = $image-Ejpeg([$quality])> =begin comment This returns the image data in JPEG format. You can then print it, pipe it to a display program, or write it to a file. You may pass an optional quality score to jpeg() in order to control the JPEG quality. This should be an integer between 0 and 100. Higher quality scores give larger files and better image quality. If you don't specify the quality, jpeg() will choose a good default. =end comment これは JPEG 形式の画像データを返します。 それを print したり、表示プログラムにパイプ経由で渡したり、 ファイルに書き出したりできます。 JPEG の画質を制御するためのオプション引数を jpeg() に渡すこともできます。 これは 0 から 100 の間の整数です。 大きい値は、大きなファイルを作りますがより良い画質になります。 画質を指定しなければ、jpeg() はいいデフォルト値を選択します。 =item B<$gifdata = $image-Egif()> =begin comment This returns the image data in GIF format. You can then print it, pipe it to a display program, or write it to a file. =end comment これは GIF 形式の画像データを返します。 それを print したり、表示プログラムにパイプ経由で渡したり、 ファイルに書き出したりできます。 =item B<$gddata = $image-Egd> =begin comment This returns the image data in GD format. You can then print it, pipe it to a display program, or write it to a file. Example: =end comment これは GD 形式の画像データを返します。 それを print したり、表示プログラムにパイプ経由で渡したり、 ファイルに書き出したりできます。例: binmode MYOUTFILE; print MYOUTFILE $myImage->gd; =item B<$gd2data = $image-Egd2> =begin comment Same as gd(), except that it returns the data in compressed GD2 format. =end comment これはほぼ gd() と同じですが、圧縮 GD2 形式のデータを返します。 =item B<$wbmpdata = $image-Ewbmp([$foreground])> =begin comment This returns the image data in WBMP format, which is a black-and-white image format. Provide the index of the color to become the foreground color. All other pixels will be considered background. =end comment これは WBMP 形式の画像データを返します。これは白黒の画像形式です。 これには、前景色となるべき色の番号を与えます。 他のすべてのピクセルは背景色と見なされます。 =back =head2 色の制御 =begin comment These methods allow you to control and manipulate the GD::Image color table. =end comment 以下のメソッドを使えば、GD::Image のカラー表を制御し、操作できます。 =over 4 =item B<$index = $image-EcolorAllocate(red,green,blue)> =begin comment This allocates a color with the specified red, green and blue components and returns its index in the color table, if specified. The first color allocated in this way becomes the image's background color. (255,255,255) is white (all pixels on). (0,0,0) is black (all pixels off). (255,0,0) is fully saturated red. (127,127,127) is 50% gray. You can find plenty of examples in /usr/X11/lib/X11/rgb.txt. =end comment これは、指定した赤、緑、青の成分を持つ色を割り当て、 それが行なえた場合はそのカラー表内の番号を返します。 この方法で割り当てられる最初の色は、画像の背景色になります。 (255,255,255) は白 (すべてのビットが On) で、 (0,0,0) は黒 (すべてのビットが Off) を意味します。 (255,0,0) は完全な赤、(127,127,127) は 50% の灰色を意味します。 非常に多くの色の見本は /usr/X11/lib/X11/rgb.txt に見ることができます。 =begin comment If no colors are allocated, then this function returns -1. =end comment 色を割り当てることができなかった場合は、この関数は -1 を返します。 例: $white = $myImage->colorAllocate(0,0,0); # 背景色 $black = $myImage->colorAllocate(255,255,255); $peachpuff = $myImage->colorAllocate(255,218,185); =item B<$index = $image-EcolorAllocateAlpha(reg,green,blue,alpha)> =begin comment This allocates a color with the specified red, green, and blue components, plus the specified alpha channel. The alpha value may range from 0 (opaque) to 127 (transparent). The C function changes the way this alpha channel affects the resulting image. =end comment これは指定した赤、緑、青の成分に加えて、 指定したアルファチャンネルを持つ色を割り当てます。 アルファ値は 0 (不透明) から 127 (透明) の間の値です。 C 関数は、このアルファチャンネルが結果の画像に どのように影響を与えるかを変更します。 =begin comment =item B<$index = $image-EcolorAllocateAlpha(reg,green,blue,alpha)> This allocates a color with the specified red, green, and blue components, plus the specified alpha channel. The alpha value may range from 0 (opaque) to 127 (transparent). The C function changes the way this alpha channel affects the resulting image. これは上と全く同じなのでカット =end comment =item B<$image-EcolorDeallocate(colorIndex)> =begin comment This marks the color at the specified index as being ripe for reallocation. The next time colorAllocate is used, this entry will be replaced. You can call this method several times to deallocate multiple colors. There's no function result from this call. =end comment これは指定した番号の色を再割り当てのための空きとしてマークします。 その色は、この次に使う colorAllocate によって置き替えられます。 このメソッドで複数の色を何度も取り消すことができます。 この呼び出しによる返り値はありません。 例: $myImage->colorDeallocate($peachpuff); $peachy = $myImage->colorAllocate(255,210,185); =item B<$index = $image-EcolorClosest(red,green,blue)> =begin comment This returns the index of the color closest in the color table to the red green and blue components specified. If no colors have yet been allocated, then this call returns -1. =end comment これは、指定した RGB の成分に最も近いカラー表中の色の番号を返します。 一つも色が割り当てられていない場合は、これは -1 を返します。 例: $apricot = $myImage->colorClosest(255,200,180); =item B<$index = $image-EcolorClosestHWB(red,green,blue)> =begin comment This also attempts to return the color closest in the color table to the red green and blue components specified. It uses a Hue/White/Black color representation to make the selected colour more likely to match human perceptions of similar colors. =end comment これも、指定した RGB の成分に最も近いカラー表中の色の番号を返そうとします。 これは Hue/White/Black 色表現を使い、 人間の感覚に取ってより近い色を選択します。 =begin comment If no colors have yet been allocated, then this call returns -1. =end comment 一つも色が割り当てられていない場合は、これは -1 を返します。 例: $mostred = $myImage->colorClosestHWB(255,0,0); =item B<$index = $image-EcolorExact(red,green,blue)> =begin comment This returns the index of a color that exactly matches the specified red green and blue components. If such a color is not in the color table, this call returns -1. =end comment これは、指定した RGB の成分に正確に一致する色の番号を返します。 そのような色がカラー表にない場合は、-1 を返します。 $rosey = $myImage->colorExact(255,100,80); warn "Everything's coming up roses.\n" if $rosey >= 0; =item B<$index = $image-EcolorResolve(red,green,blue)> =begin comment This returns the index of a color that exactly matches the specified red green and blue components. If such a color is not in the color table and there is room, then this method allocates the color in the color table and returns its index. =end comment これは、指定した RGB の成分に正確に一致する色の番号を返します。 そのような色がカラー表になくて、まだ表に空きがある場合は、 このメソッドはその指定した RGB の色をカラー表に割り当て、 その番号を返します。 $rosey = $myImage->colorResolve(255,100,80); warn "Everything's coming up roses.\n" if $rosey >= 0; =item B<$colorsTotal = $image-EcolorsTotal> I =begin comment This returns the total number of colors allocated in the object. =end comment これはオブジェクトに割り当てられている色の総数を返します。 $maxColors = $myImage->colorsTotal; =begin comment In the case of a TrueColor image, this call will return undef. =end comment TrueColor 画像では、これは undef を返します。 =item B<$index = $image-EgetPixel(x,y)> I =begin comment This returns the color table index underneath the specified point. It can be combined with rgb() to obtain the rgb color underneath the pixel. =end comment これは、指定した点のところの色番号を返します。 これを rgb() と組合せることで、点の RGB 値を得ることもできます。 例: $index = $myImage->getPixel(20,100); ($r,$g,$b) = $myImage->rgb($index); =item B<($red,$green,$blue) = $image-Ergb($index)> =begin comment This returns a list containing the red, green and blue components of the specified color index. =end comment これは、指定した色番号の RGB 成分のリストを返します。 例: @RGB = $myImage->rgb($peachy); =item B<$image-Etransparent($colorIndex)> =begin comment This marks the color at the specified index as being transparent. Portions of the image drawn in this color will be invisible. This is useful for creating paintbrushes of odd shapes, as well as for making PNG backgrounds transparent for displaying on the Web. Only one color can be transparent at any time. To disable transparency, specify -1 for the index. =end comment これは、指定した番号の色を透明色用にマークします。 画像の中のこの色で描かれた部分は表示されなくなります。 これは、変わった形の絵筆 (paint brush) を作るのに有用で、 Web 上での表示用に背景の透明な PNG 画像を作るのと同様です。 どんな場合でも 1 色のみが透明化可能です。 透明化を無効にするには、色番号として -1 を指定してください。 =begin comment If you call this method without any parameters, it will return the current index of the transparent color, or -1 if none. =end comment このメソッドをパラメータを指定せずに呼び出した場合、 これは現在の透明化色の番号を、それがなければ -1 を返します。 例: open(PNG,"test.png"); $im = newFromPng GD::Image(PNG); $white = $im->colorClosest(255,255,255); # 白を検索 $im->transparent($white); binmode STDOUT; print $im->png; =back =head2 特別な色 =begin comment GD implements a number of special colors that can be used to achieve special effects. They are constants defined in the GD:: namespace, but automatically exported into your namespace when the GD module is loaded. =end comment GD は、特殊な効果のための特別な色名をいくつか実装しています。 これらは GD:: の名前空間で定義された定数で、 しかし、GD モジュールをロードすれば 自動的にあなたの名前空間内で使用できます。 =over 4 =item B<$image-EsetBrush($image)> =begin comment You can draw lines and shapes using a brush pattern. Brushes are just images that you can create and manipulate in the usual way. When you draw with them, their contents are used for the color and shape of the lines. =end comment 筆先 (brush) パターンを使って線や形を描くことができます。 筆先とは単なる画像で、通常の方法で作成、処理できます。 その絵筆で描くと、その線の色や形にその画像のものが使用されます。 =begin comment To make a brushed line, you must create or load the brush first, then assign it to the image using setBrush(). You can then draw in that with that brush using the B special color. It's often useful to set the background of the brush to transparent so that the non-colored parts don't overwrite other parts of your image. =end comment 絵筆で線を描くには、まず筆先画像を作るか読み込む必要があります。 その後、それを setBrush() で使われる画像に割り当てます。 そうすれば、B という特別な色名を指定することで、 この絵筆で描画できます。 例: # 角度を持つ筆先の生成 $diagonal_brush = new GD::Image(5,5); $white = $diagonal_brush->colorAllocate(255,255,255); $black = $diagonal_brush->colorAllocate(0,0,0); $diagonal_brush->transparent($white); $diagonal_brush->line(0,4,4,0,$black); # 北東方向の対角線 # 筆先の設定 $myImage->setBrush($diagonal_brush); # その筆先で円を描く $myImage->arc(50,50,25,25,0,360,gdBrushed); =item B<$image-EsetThickness($thickness)> =begin comment Lines drawn with line(), rectangle(), arc(), and so forth are 1 pixel thick by default. Call setThickness() to change the line drawing width. =end comment line(), rectangle(), arc() などで描かれる線の太さのデフォルトは 1 ピクセルです。setThickness() を呼ぶことでその線の幅を変更できます。 =item B<$image-EsetStyle(@colors)> =begin comment Styled lines consist of an arbitrary series of repeated colors and are useful for generating dotted and dashed lines. To create a styled line, use setStyle() to specify a repeating series of colors. It accepts an array consisting of one or more color indexes. Then draw using the B special color. Another special color, B can be used to introduce holes in the line, as the example shows. =end comment 任意の並びの色の繰返しパターンからなる線は、 点線や破線を生成するのに有用です。 そのような線種を生成するには、色の並びの繰り返しを setStyle() に指定します。 これは一つ、または複数の色番号からなる配列を受け付けます。 そしてその後で B という特別な色名を指定して描画します。 B は、以下の例にあるように、線に穴を作るときに使われます。 例: =begin comment # Set a style consisting of 4 pixels of yellow, # 4 pixels of blue, and a 2 pixel gap =end comment # 4 ピクセルの黄色、4 ピクセルの青、2 ピクセルの # 空白からなる線種を設定 $myImage->setStyle($yellow,$yellow,$yellow,$yellow, $blue,$blue,$blue,$blue, gdTransparent,gdTransparent); $myImage->arc(50,50,25,25,0,360,gdStyled); =begin comment To combine the C and C behaviors, you can specify C. In this case, a pixel from the current brush pattern is rendered wherever the color specified in setStyle() is neither gdTransparent nor 0. =end comment C と C を組み合わせるには、 C を使います。 この場合、setStyle() で指定した色が gdTransparent でも 0 でもない 全ての場所で、現在の絵筆パターンのピクセルが使用されます。 =item B =begin comment Draw filled shapes and flood fills using a pattern. The pattern is just another image. The image will be tiled multiple times in order to fill the required space, creating wallpaper effects. You must call C in order to define the particular tile pattern you'll use for drawing when you specify the gdTiled color. details. =end comment これは、あるパターンを用いて図形内部を塗り潰します。 そのパターンは別な画像です。 その画像を、要求された領域を埋めるように複数回タイル張りし、 それにより壁紙の効果が得られます。 特定のタイルパターンを定義するためには、 C を呼び出す必要があり、 その後で gdTiled 色を使って描画できます。 =item B =begin comment The gdStyled color is used for creating dashed and dotted lines. A styled line can contain any series of colors and is created using the setStyled() command. =end comment gdStyled 色は点線、破線を生成するのに使われます。 その線種は、任意の色の並びを指定でき、setStyled() コマンドで作成します。 =item B =begin comment The C color is used for drawing lines with antialiasing turned on. Antialiasing will blend the jagged edges of lines with the background, creating a smoother look. The actual color drawn is set with setAntiAliased(). =end comment C 色は、 アンチエイリアスを On にした線を描画するのに使われます。 アンチエイリアスは、線のギザギザの端に背景色を混ぜることで 滑らかに見える線を生成します。 実際の描画色は、setAntiAliased() で設定します。 =item B<$image-EsetAntiAliased($color)> =begin comment "Antialiasing" is a process by which jagged edges associated with line drawing can be reduced by blending the foreground color with an appropriate percentage of the background, depending on how much of the pixel in question is actually within the boundaries of the line being drawn. All line-drawing methods, such as line() and polygon, will draw antialiased lines if the special "color" B is used when calling them. =end comment "アンチエイリアス" は、線の描画の際のギザギザの端に、 前景色と適当な割合の背景色を混ぜることで補正する方法で、 それは、描画される線の境界に実際に問題となるピクセルが どれくらいの数含まれるかに依存します。 呼び出しのときに特別な "色" として B を使うことによって、 line() や多角形などの線の描画メソッド全てで アンチエイリアスされた線が使われます。 =begin comment setAntiAliased() is used to specify the actual foreground color to be used when drawing antialiased lines. You may set any color to be the foreground, however as of libgd version 2.0.12 an alpha channel component is not supported. =end comment アンチエイリアスの線を描画する際に使用される実際の前景色は、 setAntiAliased() を使って指定します。 任意の色を前景色に指定できますが、 libgd version 2.0.12 現在ではアルファチャンネル成分は サポートされていません。 =begin comment Antialiased lines can be drawn on both truecolor and palette-based images. However, attempts to draw antialiased lines on highly complex palette-based backgrounds may not give satisfactory results, due to the limited number of colors available in the palette. Antialiased line-drawing on simple backgrounds should work well with palette-based images; otherwise create or fetch a truecolor image instead. =end comment アンチエイリアスの線は、truecolor 画像、 パレットベースの画像の両方で使用できます。 しかし、パレットベースのかなり複雑な背景の上に アンチエイリアス線を描こうとすると、 残念ながらあまりうまくいきません。 それはパレットでは使える色に限りがあるためです。 単純な背景の上なら、パレットベース画像でもうまくいくでしょう。 そうでなければ代わりに truecolor 画像を作るか持ってくるかしてください。 =item B<$image-EsetAntiAliasedDontBlend($color,[$flag])> =begin comment Normally, when drawing lines with the special B "color," blending with the background to reduce jagged edges is the desired behavior. However, when it is desired that lines not be blended with one particular color when it is encountered in the background, the setAntiAliasedDontBlend() method can be used to indicate the special color that the foreground should stand out more clearly against. =end comment 通常は、特別な B "色" で描画する場合、 ギザギザの端を補正するために背景色の混合が行われます。 しかし、線が背景である特殊な色に出会ったときに その線にその色が混ぜられないことを望む場合、 前景色がより明確に目立つような特別な色を指定するのに setAntiAliasedDontBlend() メソッドを使うことができます。 =begin comment Once turned on, you can turn this feature off by calling setAntiAliasedDontBlend() with a second argument of 0: =end comment 一度これを On にした後は、setAntiAliasedDontBlend() の第 2 引数を 0 にして呼び出すことでこの機能を Off にできます。 $image->setAntiAliasedDontBlend($color,0); =back =head2 描画コマンド =begin comment These methods allow you to draw lines, rectangles, and elipses, as well as to perform various special operations like flood-fill. =end comment 以下のメソッドによって線、長方形、楕円を描画し、 さらに閉領域の塗りつぶしのようないくつかの特殊な操作も行えます。 =over 4 =item B<$image-EsetPixel($x,$y,$color)> =begin comment This sets the pixel at (x,y) to the specified color index. No value is returned from this method. The coordinate system starts at the upper left at (0,0) and gets larger as you go down and to the right. You can use a real color, or one of the special colors gdBrushed, gdStyled and gdStyledBrushed can be specified. =end comment これは、(x,y) のピクセルを、指定した色番号に設定します。 このメソッドの返り値はありません。 座標系は、左上の角が (0,0) で、右、下に向かって座標値は増えていきます。 色は普通の色の他に、特別な色指定である gdBrushed, gdStyled, gdStyledBrushed を使うこともできます。 例: # $peach が既に割り当てられているとして $myImage->setPixel(50,50,$peach); =item B<$image-Eline($x1,$y1,$x2,$y2,$color)> =begin comment This draws a line from (x1,y1) to (x2,y2) of the specified color. You can use a real color, or one of the special colors gdBrushed, gdStyled and gdStyledBrushed. =end comment これは (x1,y1) から (x2,y2) への指定した色での線分を引きます。 色は普通の色の他に、特別な色指定である gdBrushed, gdStyled, gdStyledBrushed を使うこともできます。 例: =begin comment # Draw a diagonal line using the currently defind # paintbrush pattern. =end comment # 現在定義されている筆先パターンで対角線を描く $myImage->line(0,0,150,150,gdBrushed); =item B<$image-EdashedLine($x1,$y1,$x2,$y2,$color)> =begin comment DEPRECATED: The libgd library provides this method solely for backward compatibility with libgd version 1.0, and there have been reports that it no longer works as expected. Please use the setStyle() and gdStyled methods as described below. =end comment 注意: libgd ライブラリは、このメソッドは単に libgd version 1.0 への 後方互換性のために提供していて、 もはや期待通りには動作しないという報告がされています。 代わりに上で説明した setStyle() と gdStyled メソッドを使ってください。 =begin comment This draws a dashed line from (x1,y1) to (x2,y2) in the specified color. A more powerful way to generate arbitrary dashed and dotted lines is to use the setStyle() method described below and to draw with the special color gdStyled. =end comment これは (x1,y1) から (x2,y2) への指定した色での破線を引きます。 任意の破線や点線を描くより強力な方法は、 上で説明した setStyle() メソッドを使い、 特別な色である gdStyled で描画することです。 例: $myImage->dashedLine(0,0,150,150,$blue); =item B<$image-Erectangle($x1,$y1,$x2,$y2,$color)> =begin comment This draws a rectangle with the specified color. (x1,y1) and (x2,y2) are the upper left and lower right corners respectively. Both real color indexes and the special colors gdBrushed, gdStyled and gdStyledBrushed are accepted. =end comment これは指定した色で長方形を描きます。 (x1,y1), (x2,y2) はそれぞれ左上と右下の角の座標です。 色は普通の色も、特別な色指定である gdBrushed, gdStyled, gdStyledBrushed も使えます。 例: $myImage->rectangle(10,10,100,100,$rose); =item B<$image-EfilledRectangle($x1,$y1,$x2,$y2,$color)> =begin comment This draws a rectangle filed with the specified color. You can use a real color, or the special fill color gdTiled to fill the polygon with a pattern. =end comment これは指定した色で塗りつぶした長方形を描きます。 色は普通の色も使えますし、多角形の塗り潰しパターン用の特別な色指定 gdTiled も使えます。 例: # 塗り潰しパターンを読み込み、それを設定 $tile = newFromPng GD::Image('happyface.png'); $myImage->setTile($tile); # 長方形を描いて、そのパターンで塗り潰す $myImage->filledRectangle(10,10,150,200,gdTiled); =item B<$image-EopenPolygon($polygon,$color)> =begin comment This draws a polygon with the specified color. The polygon must be created first (see below). The polygon must have at least three vertices. If the last vertex doesn't close the polygon, the method will close it for you. Both real color indexes and the special colors gdBrushed, gdStyled and gdStyledBrushed can be specified. =end comment これは指定した色で多角形を描きます。 最初に多角形 (polygon) を作っておく必要があります (以下参照)。 多角形は 3 点以上が必要です。 最後の頂点が多角形を閉じていない場合、 このメソッドはそれを閉じます。 色は普通の色番号も、特別な色指定である gdBrushed, gdStyled, gdStyledBrushed も使えます。 例: $poly = new GD::Polygon; $poly->addPt(50,0); $poly->addPt(99,99); $poly->addPt(0,99); $myImage->openPolygon($poly,$blue); =item B<$image-EunclosedPolygon($polygon,$color)> =begin comment This draws a sequence of connected lines with the specified color, without connecting the first and last point to a closed polygon. The polygon must be created first (see below). The polygon must have at least three vertices. Both real color indexes and the special colors gdBrushed, gdStyled and gdStyledBrushed can be specified. =end comment これは、指定した色で折れ線を描画し、 閉じた多角形にするための最初の点と最後の点を結ぶことは行いません。 最初に多角形 (polygon) を作っておく必要があります (以下参照)。 多角形は 3 点以上が必要です。 色は普通の色番号も、特別な色指定である gdBrushed, gdStyled, gdStyledBrushed も使えます。 =begin comment You need libgd 2.0.33 or higher to use this feature. =end comment この機能を使うには、libgd 2.0.33 以上が必要です。 例: $poly = new GD::Polygon; $poly->addPt(50,0); $poly->addPt(99,99); $poly->addPt(0,99); $myImage->unclosedPolygon($poly,$blue); =item B<$image-EfilledPolygon($poly,$color)> =begin comment This draws a polygon filled with the specified color. You can use a real color, or the special fill color gdTiled to fill the polygon with a pattern. =end comment これは、指定した色で塗り潰された多角形を描画します。 色は普通の色も使えますし、多角形の塗り潰しパターン用の特別な色指定 gdTiled も使えます。 例: # 多角形を作る $poly = new GD::Polygon; $poly->addPt(50,0); $poly->addPt(99,99); $poly->addPt(0,99); # 多角形を描いて、色で塗り潰す $myImage->filledPolygon($poly,$peachpuff); =item B<$image-Eellipse($cx,$cy,$width,$height,$color)> =item B<$image-EfilledEllipse($cx,$cy,$width,$height,$color)> =begin comment These methods() draw ellipses. ($cx,$cy) is the center of the arc, and ($width,$height) specify the ellipse width and height, respectively. filledEllipse() is like Ellipse() except that the former produces filled versions of the ellipse. =end comment これらのメソッドは楕円を描画します。 ($cx,$cy) は楕円の中心で、 ($width,$height) はそれぞれ楕円の横幅と高さです。 filledEllipse() は Ellipse() とほぼ同様ですが、前者は楕円を塗り潰します。 =item B<$image-Earc($cx,$cy,$width,$height,$start,$end,$color)> =begin comment This draws arcs and ellipses. (cx,cy) are the center of the arc, and (width,height) specify the width and height, respectively. The portion of the ellipse covered by the arc are controlled by start and end, both of which are given in degrees from 0 to 360. Zero is at the top of the ellipse, and angles increase clockwise. To specify a complete ellipse, use 0 and 360 as the starting and ending angles. To draw a circle, use the same value for width and height. =end comment これは楕円の弧を描画します。(cx,cy) は中心、 (width,height) はそれぞれ横幅と高さです。 楕円の一部分の指定は、start と end で行い、 これらは 0 から 360 までの角度を意味します。 角度は 0 度が楕円のてっぺんで、時計回りに増加すると考えます (訳注: 実際には 0 度は右端を意味するよう)。 円弧を描くには、width と height を同じ値にします。 =begin comment You can specify a normal color or one of the special colors B, B, or B. =end comment 色は普通の色も、特別な色指定である B, B, B も使えます。 例: # 100,100 中心の半円を描画 $myImage->arc(100,100,50,50,0,180,$blue); =item B<$image-EfilledArc($cx,$cy,$width,$height,$start,$end,$color [,$arc_style])> =begin comment This method is like arc() except that it colors in the pie wedge with the selected color. $arc_style is optional. If present it is a bitwise OR of the following constants: =end comment このメソッドは arc() 同様ですが、選択した色で扇形部分を塗り潰します。 $arc_style はオプション引数です。 それはビット毎の OR で与えられ、以下の意味を持ちます: =begin comment gdArc connect start & end points of arc with a rounded edge gdChord connect start & end points of arc with a straight line gdPie synonym for gdChord gdNoFill outline the arc or chord gdEdged connect beginning and ending of the arc to the center =end comment gdArc 開始点と終了点を楕円弧で結ぶ gdChord 開始点と終了点を直線で結ぶ gdPie gdArc と同義 gdNoFill 弧または弦の部分のみ描画 gdEdged 中心と開始点、中心と終了点をそれぞれ結ぶ =begin comment gdArc and gdChord are mutally exclusive. gdChord just connects the starting and ending angles with a straight line, while gdArc produces a rounded edge. gdPie is a synonym for gdArc. gdNoFill indicates that the arc or chord should be outlined, not filled. gdEdged, used together with gdNoFill, indicates that the beginning and ending angles should be connected to the center; this is a good way to outline (rather than fill) a "pie slice." =end comment gdArc と gdChord は互いに排他的です。 gdArc が開始点と終了点を楕円弧で結ぶのに対して、 gdChord は直線 (弦) で結びます。 gdPie は gdArc と同義です。 gdNoFill は弧、または弦のみを描画することを意味し、 内部の塗り潰しは行いません。 gdEdged を gdNoFill と一緒に使えば、 これは開始点と中心、これは終了点と中心も結びます。 これは、(塗り潰さない) "扇形" を得るやり方の一つです。 例: $image->filledArc(100,100,50,50,0,90,$blue,gdEdged|gdNoFill); =item B<$image-Efill($x,$y,$color)> =begin comment This method flood-fills regions with the specified color. The color will spread through the image, starting at point (x,y), until it is stopped by a pixel of a different color from the starting pixel (this is similar to the "paintbucket" in many popular drawing toys). You can specify a normal color, or the special color gdTiled, to flood-fill with patterns. =end comment このメソッドは、領域を指定した色で塗り潰します。 その色は点 (x,y) から始まって、 それが開始位置のピクセルと違う色の所に出会うまで 画像全体に広がっていきます。 これは、多くのポピュラーな描画ツールが持つ "色バケツ (paint bucket)" の機能と同様です。 色は普通の色も使えますし、塗り潰しパターン用の特別な色指定 gdTiled も使えます。 例: # 長方形を描き、その内部を青にする $myImage->rectangle(10,10,100,100,$black); $myImage->fill(50,50,$blue); =item B<$image-EfillToBorder($x,$y,$bordercolor,$color)> =begin comment Like C, this method flood-fills regions with the specified color, starting at position (x,y). However, instead of stopping when it hits a pixel of a different color than the starting pixel, flooding will only stop when it hits the color specified by bordercolor. You must specify a normal indexed color for the bordercolor. However, you are free to use the gdTiled color for the fill. =end comment C と同様に、このメソッドは点 (x,y) から始めて 領域を指定した色で塗り潰します。 しかし、開始位置のピクセルと違う色の所に出会ったところでやめる代わりに、 これは bordercolor で指定した色に出会ったところでやめます。 bordercolor は、普通の色番号を指定する必要があります。 しかし、塗り潰しの色には gdTiled を使っても構いません。 例: # 前の例と同じになる $myImage->rectangle(10,10,100,100,$black); $myImage->fillToBorder(50,50,$black,$blue); =back =head2 画像コピーコマンド =begin comment Two methods are provided for copying a rectangular region from one image to another. One method copies a region without resizing it. The other allows you to stretch the region during the copy operation. =end comment 一つの画像から長方形領域を別な画像にコピーするメソッドが 2 つ用意されています。 一つはサイズの変更なしに領域をコピーするメソッドで、 もう一つはコピー操作とともに領域の引きのばしが行なえます。 =begin comment With either of these methods it is important to know that the routines will attempt to flesh out the destination image's color table to match the colors that are being copied from the source. If the destination's color table is already full, then the routines will attempt to find the best match, with varying results. =end comment これらのメソッドのそれぞれで、 そのルーチンは元の画像からコピーされる領域の色を対応させるために、 コピー先の画像のカラー表を書き直そうとすることを覚えておいてください。 コピー先のカラー表が既に一杯の場合は、 そのルーチンはその中で最もうまく合わせようとしますが、 結果として変化してしまいます。 =over 4 =item B<$image-Ecopy($sourceImage,$dstX,$dstY,> B< $srcX,$srcY,$width,$height)> =begin comment This is the simplest of the several copy operations, copying the specified region from the source image to the destination image (the one performing the method call). (srcX,srcY) specify the upper left corner of a rectangle in the source image, and (width,height) give the width and height of the region to copy. (dstX,dstY) control where in the destination image to stamp the copy. You can use the same image for both the source and the destination, but the source and destination regions must not overlap or strange things will happen. =end comment これは、 元の画像から指定された領域をコピー先の画像へコピーする、 いくつかのコピー操作関数の中で最も単純なものです。 (srcX,srcY) は、コピー元の画像での長方形の左上の座標、 (width,height) はコピーする長方形領域の幅と高さです。 (dstX,dstY) は、コピー先の画像にそれを置く場所の指定です。 コピー元とコピー先が同じ画像であっても構いませんが、 その場合コピー元の領域とコピー先の領域が重なってはいけません。 そうでないと予期せぬ結果を招く恐れがあります。 例: $myImage = new GD::Image(100,100); ... 色々な描画命令等 ... $srcImage = new GD::Image(50,50); ... さらなる描画命令等 ... # $srcImage から 25x25 ピクセルを、$myImage の # (10,10) から始まる長方形にコピー $myImage->copy($srcImage,10,10,0,0,25,25); =item B<$image-Eclone()> =begin comment Make a copy of the image and return it as a new object. The new image will look identical. However, it may differ in the size of the color palette and other nonessential details. =end comment これは画像のコピーを生成して、それを新しいオブジェクトとして返します。 新しい画像は全く同じに見えるものになります。 しかし、そのカラーパレットのサイズや他の本質的でない部分は 違っているかもしれません。 例: $myImage = new GD::Image(100,100); ... 色々な描画命令等 ... $copy = $myImage->clone; =item B<$image-EcopyMerge($sourceImage,$dstX,$dstY,> B< $srcX,$srcY,$width,$height,$percent)> =begin comment This copies the indicated rectangle from the source image to the destination image, merging the colors to the extent specified by percent (an integer between 0 and 100). Specifying 100% has the same effect as copy() -- replacing the destination pixels with the source image. This is most useful for highlighting an area by merging in a solid rectangle. =end comment これは元の画像の指定した長方形をコピー先の画像にコピーしますが、 色を指定したパーセント (0 から 100 までの整数) で合成します。 100% を指定すれば copy() と同じで、コピー先のピクセルを 完全にコピー元の画像で置き替えます。 これは塗り潰された長方形で合成することで、 ある部分を強調したりするのに最も有用でしょう。 例: $myImage = new GD::Image(100,100); ... 色々な描画命令等 ... $redImage = new GD::Image(50,50); ... さらなる描画命令等 ... # $srcImage から 25x25 ピクセルを、$myImage の # (10,10) から始まる長方形に、50% の混合率でコピー $myImage->copyMerge($srcImage,10,10,0,0,25,25,50); =item B<$image-EcopyMergeGray($sourceImage,$dstX,$dstY,> B< $srcX,$srcY,$width,$height,$percent)> =begin comment This is identical to copyMerge() except that it preserves the hue of the source by converting all the pixels of the destination rectangle to grayscale before merging. =end comment これは copyMerge() とほぼ同じですが、 混合する前にコピー先の長方形の全てのピクセルを灰色階調に変換することで、 元の画像の色相を変化させないようにします。 =item B<$image-EcopyResized($sourceImage,$dstX,$dstY,> B< $srcX,$srcY,$destW,$destH,$srcW,$srcH)> =begin comment This method is similar to copy() but allows you to choose different sizes for the source and destination rectangles. The source and destination rectangle's are specified independently by (srcW,srcH) and (destW,destH) respectively. copyResized() will stretch or shrink the image to accomodate the size requirements. =end comment このメソッドは copy() とほぼ同じですが、 コピー元とコピー先の長方形を違うサイズに選択することができます。 コピー元とコピー先の長方形のサイズはそれぞれ (srcW,srcH), (destW,destH) で独立に指定できます。 copyResized() は要求したサイズに合わせるために拡大や縮小を行います。 例: $myImage = new GD::Image(100,100); ... 色々な描画命令等 ... $srcImage = new GD::Image(50,50); ... さらなる描画命令等 ... # $srcImage から 25x25 ピクセルを、$myImage の # (10,10) から始まる大きい長方形にコピー $myImage->copyResized($srcImage,10,10,0,0,50,50,25,25); =item B<$image-EcopyResampled($sourceImage,$dstX,$dstY,> B< $srcX,$srcY,$destW,$destH,$srcW,$srcH)> =begin comment This method is similar to copyResized() but provides "smooth" copying from a large image to a smaller one, using a weighted average of the pixels of the source area rather than selecting one representative pixel. This method is identical to copyResized() when the destination image is a palette image. =end comment このメソッドは copyResized() と同様ですが、 大きな画像から小さな画像にコピーする際に、 一つの代表のピクセルを選択するのではなく、 原画像の重みつきの平均を使って "滑らか" なコピーを行ないます。 このメソッドは、コピー先の画像がパレット画像の場合には、 copyResize() と全く同じになります。 =item B<$image-EcopyRotated($sourceImage,$dstX,$dstY,> B< $srcX,$srcY,$width,$height,$angle)> =begin comment Like copyResized() but the $angle argument specifies an arbitrary amount to rotate the image clockwise (in degrees). In addition, $dstX and $dstY species the B
of the destination image, and not the topleft corner. =end comment これは copyResize() と似ていますが、引数 $angle には 画像を時計回りに回転する任意の角度 (単位は度) を指定します。 なお、$dstX, $dstY は、コピー先の左上の角ではなくて、 コピー先の領域の B<中心> を意味します。 =item B<$image-EtrueColorToPalette([$dither], [$colors])> =begin comment This method converts a truecolor image to a palette image. The code for this function was originally drawn from the Independent JPEG Group library code, which is excellent. The code has been modified to preserve as much alpha channel information as possible in the resulting palette, in addition to preserving colors as well as possible. This does not work as well as might be hoped. It is usually best to simply produce a truecolor output image instead, which guarantees the highest output quality. Both the dithering (0/1, default=0) and maximum number of colors used (<=256, default = gdMaxColors) can be specified. =end comment このメソッドは、truecolor 画像をパレット画像ニ変換します。 この関数のソースコードは、元は Independent JPEG Group library で書かれたコードで、これはとても優れたものです。 そのコードを、アルファチャンネル情報を結果のパレット内に できるだけ多く残せるように改良し、 色数も可能な限り残せるように修正したものです。 しかしこれは、期待される程のことを行ってはくれません。 通常は、代わりに単に truecolor 画像出力を作るのが最も良くて、 最高の画質の出力が保証されます。 ディザ化オプション $dither (0/1, デフォルト=0) と 使用した色数の最大数 $colors (<=256, デフォルト = gdMaxColors) を指定できます。 =back =head2 画像変換コマンド =begin comment Gd also provides some common image transformations: =end comment Gd はいくつか一般的な画像変換も提供しています: =over 4 =item B<$image = $sourceImage-EcopyRotate90()> =item B<$image = $sourceImage-EcopyRotate180()> =item B<$image = $sourceImage-EcopyRotate270()> =item B<$image = $sourceImage-EcopyFlipHorizontal()> =item B<$image = $sourceImage-EcopyFlipVertical()> =item B<$image = $sourceImage-EcopyTranspose()> =item B<$image = $sourceImage-EcopyReverseTranspose()> =begin comment These methods can be used to rotate, flip, or transpose an image. The result of the method is a copy of the image. =end comment これらのメソッドは、回転、対称変換、転置などに使われます。 メソッドの返り値は画像のコピーです。 =item B<$image-Erotate180()> =item B<$image-EflipHorizontal()> =item B<$image-EflipVertical()> =begin comment These methods are similar to the copy* versions, but instead modify the image in place. =end comment これらのメソッドは copy* 版と同様ですが、 代わりに画像をその結果で置き替えます。 =back =head2 文字と文字列の描画 =begin comment GD allows you to draw characters and strings, either in normal horizontal orientation or rotated 90 degrees. These routines use a GD::Font object, described in more detail below. There are four built-in monospaced fonts, available in the global variables B, B, B, B and B. =end comment GD は文字や文字列を、通常の水平方向にも、90 度回転させても描画できます。 以下のルーチンは GD::Font オブジェクトを使用します。 詳細は以下を参照してください。 あらかじめ組み込まれたモノスペースなフォントが 5 種類あり、 それらは大域変数 B, B, B, B, B で参照可能です。 =begin comment In addition, you can use the load() method to load GD-formatted bitmap font files at runtime. You can create these bitmap files from X11 BDF-format files using the bdf2gd.pl script, which should have been installed with GD (see the bdf_scripts directory if it wasn't). The format happens to be identical to the old-style MSDOS bitmap ".fnt" files, so you can use one of those directly if you happen to have one. =end comment さらに、実行時に load() メソッドを使って GD 形式のビットマップフォントを 読み込むこともできます。 GD とともにインストールされるスクリプト bdf2gd.pl (ないようなら bdf_script ディレクトリを参照してください) を使えば X11 BDF 形式のフォントファイルから その形式のビットマップフォントを作成することができます。 その形式のフォントは、古い MSDOS ビットマップ形式の ".fnt" ファイルと 一致する可能性があるので、それを持っているならそのうちの一つを直接 使うこともできます。 =begin comment For writing proportional scaleable fonts, GD offers the stringFT() method, which allows you to load and render any TrueType font on your system. =end comment プロポーショナルなスケーラブルフォントを使うには、 GD の stringFT() メソッドで、システムにある任意の TrueType フォントを ロードして描画することができます。 =over 4 =item B<$image-Estring($font,$x,$y,$string,$color)> =begin comment This method draws a string startin at position (x,y) in the specified font and color. Your choices of fonts are gdSmallFont, gdMediumBoldFont, gdTinyFont, gdLargeFont and gdGiantFont. =end comment このメソッドは、指定したフォントと指定した色で (x,y) の位置から 文字列を描画します。フォントは gdSmallFont, gdMediumBoldFont, gdTinyFont, gdLargeFont, gdGiantFont から選べます。 例: $myImage->string(gdSmallFont,2,10,"Peachy Keen",$peach); =item B<$image-EstringUp($font,$x,$y,$string,$color)> =begin comment Just like the previous call, but draws the text rotated counterclockwise 90 degrees. =end comment これは string() と同様ですが、これは文字列を反時計回りに 90 度回して 描画します。 =item B<$image-Echar($font,$x,$y,$char,$color)> =item B<$image-EcharUp($font,$x,$y,$char,$color)> =begin comment These methods draw single characters at position (x,y) in the specified font and color. They're carry-overs from the C interface, where there is a distinction between characters and strings. Perl is insensible to such subtle distinctions. =end comment このメソッドは,指定したフォントと指定した色で (x,y) の位置から 一文字を描画します。 これらは、文字と文字列に違いがある C 言語のインターフェースを 持ってきただけのものです。 Perl ではそのような微々たる違いを意識する必要はないでしょう。 =item $font = Bload($fontfilepath)> =begin comment This method dynamically loads a font file, returning a font that you can use in subsequent calls to drawing methods. For example: =end comment このメソッドは、動的にフォントファイルを読み込み、 フォントを返します。 それにより、この後の描画メソッドでこれを使用することが できるようになります。 my $courier = GD::Font->load('./courierR12.fnt') or die "Can't load font"; $image->string($courier,2,10,"Peachy Keen",$peach); =begin comment Font files must be in GD binary format, as described above. =end comment フォントファイルは、上で述べた GD バイナリ形式である必要があります。 =item B<@bounds = $image-EstringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string)> =item B<@bounds = GD::Image-EstringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string)> =item B<@bounds = $image-EstringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string,\%options)> =begin comment This method uses TrueType to draw a scaled, antialiased string using the TrueType vector font of your choice. It requires that libgd to have been compiled with TrueType support, and for the appropriate TrueType font to be installed on your system. =end comment このメソッドは、選択した TrueType ベクトルフォントを使って スケーラブルなアンチエイリアスの文字列を描画します。 これは、libgd が TrueType をサポートしてコンパイルされていて、 システムに適当な TrueType フォントがインストールされている必要があります。 =begin comment The arguments are as follows: =end comment この引数は以下の通りです: =begin comment fgcolor Color index to draw the string in fontname A path to the TrueType (.ttf) font file or a font pattern. ptsize The desired point size (may be fractional) angle The rotation angle, in radians (positive values rotate counter clockwise) x,y X and Y coordinates to start drawing the string string The string itself =end comment fgcolor 文字列を描画する色番号 fontname TrueType (.ttf) のフォントファイルへのパス、またはフォントパターン ptsize ポイントサイズ (小数も可) angle 回転角度 (反時計回り、正の値) x,y 文字列の描画を始める座標 string 文字列自身 =begin comment If successful, the method returns an eight-element list giving the boundaries of the rendered string: =end comment 成功した場合、このメソッドは 8 つの要素からなるリストを返しますが、 描画した文字列の境界を与えます: =begin comment @bounds[0,1] Lower left corner (x,y) @bounds[2,3] Lower right corner (x,y) @bounds[4,5] Upper right corner (x,y) @bounds[6,7] Upper left corner (x,y) =end comment @bounds[0,1] 左下の角の (x,y) 座標 @bounds[2,3] 右下の角の (x,y) 座標 @bounds[4,5] 右上の角の (x,y) 座標 @bounds[6,7] 左上の角の (x,y) 座標 =begin comment In case of an error (such as the font not being available, or FT support not being available), the method returns an empty list and sets $@ to the error message. =end comment エラーの場合 (フォントが見つからないとか、FT のサポートがない場合など)、 このメソッドは空のリストを返し、$@ にエラーメッセージを設定します。 =begin comment The string may contain UTF-8 sequences like: "À" =end comment 文字列には、"À" のような UTF-8 列を入れることも可能です。 =begin comment You may also call this method from the GD::Image class name, in which case it doesn't do any actual drawing, but returns the bounding box using an inexpensive operation. You can use this to perform layout operations prior to drawing. =end comment このメソッドを GD::Image クラス名から呼び出すこともできます。 この場合、それは実際の描画は行いませんが、 手間のかからない作業で bounding box を返してくれますので、 これを、描画の前にレイアウトの操作を行うのに使うことができます。 =begin comment Using a negative color index will disable anti-aliasing, as described in the libgd manual page at L. =end comment 負の色番号を使用すると、libgd のマニュアルページ L. に書いてあるようにアンチエイリアスは行わなくなります。 =begin comment An optional 8th argument allows you to pass a hashref of options to stringFT(). Several hashkeys are recognized: B, B, B, and B. =end comment 8 番目のオプション引数には、stringFT() へのオプションのハッシュ参照を 渡すことができます。ハッシュキーは以下のように認識されます: B, B, B, B. =begin comment The value of B is supposed to be a multiple of the character height, so setting linespacing to 2.0 will result in double-spaced lines of text. However the current version of libgd (2.0.12) does not do this. Instead the linespacing seems to be double what is provided in this argument. So use a spacing of 0.5 to get separation of exactly one line of text. Iln practice, a spacing of 0.6 seems to give nice results. Another thing to watch out for is that successive lines of text should be separated by the "\r\n" characters, not just "\n". =end comment B の値は行間で、文字の高さに対する倍数とみなされます。 よってこれを 2.0 と設定すれば文書がダブルスペースになるはずですが、 現在の版 (2.0.12) の libgd はそうはしてくれず、 代わりに、この引数に何が与えられても linespacing はその 2 倍になるようです。 よって、行間を丁度 1 行分にしたい場合は 0.5 と指定してください。 実際には 0.6 辺りがいい結果になるようです。 他に、文章の行と行の間は "\n" ではなくて、"\r\n" で区切るべきであることに 注意点してください。 =begin comment The value of B is one of "Unicode", "Shift_JIS" and "Big5". The interaction between Perl, Unicode and libgd is not clear to me, and you should experiment a bit if you want to use this feature. =end comment B の値は、"Unicode", "Shift_JIS", "Big5" のいずれかです。 Perl と Unicode と libgd の間の相互作用に関しては詳しくないので、 この機能を使いたい場合は、少しテストをしてみてください。 =begin comment The value of B is the vertical and horizontal resolution, in DPI, in the format "hdpi,vdpi". If present, the resolution will be passed to the Freetype rendering engine as a hint to improve the appearance of the rendered font. =end comment B の値は DPI 単位での垂直方向、水平方向の改造度で、 "hdpi,vdpi" の形式です。 これが与えられた場合、解像度は描画されるフォントの見た目を改善する ヒントとして Freetype レンダリングエンジンに渡されます。 =begin comment The value of B is a flag. Set it to false to turn off the default kerning of text. =end comment B の値はフラグです。これを false に設定すると 文章のデフォルトのカーニングを Off にします。 例: $gd->stringFT($black,'/dosc/windows/Fonts/pala.ttf',40,0,20,90, "hi there\r\nbye now", {linespacing=>0.6, charmap => 'Unicode', }); =begin comment If GD was compiled with fontconfig support, and the fontconfig library is available on your system, then you can use a font name pattern instead of a path. Patterns are described in L and will look something like this "Times:italic". For backward compatibility, this feature is disabled by default. You must enable it by calling useFontConfig(1) prior to the stringFT() call. =end comment GD が fontconfig をサポートするようにコンパイルされていて、 fontconfig ライブラリがシステムで利用可能である場合は、 フォントパスの代わりにフォント名のパターンを使うことができます。 パターンは L に記述されていて、 例えば "Times:italic" のような形式です。 後方互換性のため、この機能はデフォルトでは Off になっています。 これを使えるようにするには、stringFT() 呼び出しの前に、 useFontConfig(1) を呼び出す必要があります。 $image->useFontConfig(1); =begin comment For backward compatibility with older versions of the FreeType library, the alias stringTTF() is also recognized. =end comment 古い版の FreeType ライブラリに関する後方互換性のため、 stringTTF() へのエイリアスも使うことができます。 =item B<$hasfontconfig = $image-EuseFontConfig($flag)> =begin comment Call useFontConfig() with a value of 1 in order to enable support for fontconfig font patterns (see stringFT). Regardless of the value of $flag, this method will return a true value if the fontconfig library is present, or false otherwise. =end comment fontconfig のフォントパターン (stringFT 参照) サポートを有効にするためには、 useFontConfig() を引数 1 で呼び出します。 $flag の値とは無関係に、このメソッドは、fontconfig ライブラリがある場合は true を返し、その他の場合は false を返します。 =item B<$result = $image->stringFTCircle($cx,$cy,$radius,$textRadius,$fillPortion,$font,$points,$top,$bottom,$fgcolor)> =begin comment This draws text in a circle. Currently (libgd 2.0.33) this function does not work for me, but the interface is provided for completeness. The call signature is somewhat complex. Here is an excerpt from the libgd manual page: =end comment これは円の中に文字列を書きます。現在 (libgd 2.0.33) のところ この関数は使えていないのですが、 インターフェースはちゃんと提供しています。 呼び出しの引数は多少複雑です。libgd のマニュアルから引用します: =begin comment Draws the text strings specified by top and bottom on im, curved along the edge of a circle of radius radius, with its center at cx and cy. top is written clockwise along the top; bottom is written counterclockwise along the bottom. textRadius determines the "height" of each character; if textRadius is 1/2 of radius, characters extend halfway from the edge to the center. fillPortion varies from 0 to 1.0, with useful values from about 0.4 to 0.9, and determines how much of the 180 degrees of arc assigned to each section of text is actually occupied by text; 0.9 looks better than 1.0 which is rather crowded. font is a freetype font; see gdImageStringFT. points is passed to the freetype engine and has an effect on hinting; although the size of the text is determined by radius, textRadius, and fillPortion, you should pass a point size that "hints" appropriately -- if you know the text will be large, pass a large point size such as 24.0 to get the best results. fgcolor can be any color, and may have an alpha component, do blending, etc. =end comment im 上に top と bottom で指定された文字列を描画しますが、 中心が cx,cy で radius を半径とする円の円周に沿って曲げて描画します。 top は円の上部に沿って時計回りに描画され、 bottom は円の下部に沿って反時計回りに描画されます。 textRadius は各文字の "高さ" を決定します。 例えば textRadius が半径の半分の場合、 文字は円周から中心に向って半分のところまで延ばされることになります。 fillPortion は 0 から 1.0 までの値で、0.4 から 0.9 辺りが都合がよく、 これは、それぞれの文字列用の 180 度の弧のどれ位の部分を 文字列が実際に占めるかを決定します。 0.9 は 1.0 よりいいようで、1.0 だと少し混んで見えます。 font は freetype フォントです。gdImageStringFT を参照してください。 point は freetype エンジンに渡され、それはヒントとしての効果を持ちます。 文字列のサイズは radius, textRadius, fillPortion で決定されますが、 適切な "ヒント" を与える point サイズも渡すべきです。 文字列が大きくなることを知っている場合、 24.0 のような大きな point サイズを渡せばいい結果が得られるでしょう。 fgcolor は任意の色で、アルファ成分を持つことも可能ですし、 混ぜることなどもできます。 =begin comment Returns a true value on success. =end comment 成功した場合は true を返します。 =back =head2 アルファチャンネル =begin comment The alpha channel methods allow you to control the way drawings are processed according to the alpha channel. When true color is turned on, colors are encoded as four bytes, in which the last three bytes are the RGB color values, and the first byte is the alpha channel. Therefore the hexadecimal representation of a non transparent RGB color will be: C=0x00(rr)(bb)(bb) =end comment アルファチャンネルメソッドによって、 アルファチャンネルに従う画像処理方法を制御できます。 true color が On である場合、色は 4 バイトで符号化されていて、 後ろの 3 バイトが RGB 色を、 最初のバイトがアルファチャンネルを意味します。 よって、非透過の RGB 色の 16 進表示は、次のようになります: C==0x00(rr)(gg)(bb) =begin comment When alpha blending is turned on, you can use the first byte of the color to control the transparency, meaning that a rectangle painted with color 0x00(rr)(bb)(bb) will be opaque, and another one painted with 0x7f(rr)(gg)(bb) will be transparent. The Alpha value must be >= 0 and <= 0x7f. =end comment アルファ混合が On の場合、 色の最初のバイトを透過の制御に使用できます。 この場合、色 0x00(rr)(gg)(bb) で塗られる長方形は非透過で、 色 0x7f(rr)(gg)(bb) で塗られるのは透明になります。 アルファ値は 0 から 0x7f までの値である必要があります。 =over 4 =item B<$image-EalphaBlending($integer)> =begin comment The alphaBlending() method allows for two different modes of drawing on truecolor images. In blending mode, which is on by default (libgd 2.0.2 and above), the alpha channel component of the color supplied to all drawing functions, such as C, determines how much of the underlying color should be allowed to shine through. As a result, GD automatically blends the existing color at that point with the drawing color, and stores the result in the image. The resulting pixel is opaque. In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel. Blending mode is not available when drawing on palette images. =end comment メソッド alphaBlending() では、truecolor 画像の 2 つの異なる描画モードが 利用可能です。 混合モード (blending mode; libgd 2.0.2 以上ではデフォルト) では、 例えば C のような全ての描画関数に提供される 色のアルファチャンネル成分は その下の色がそれを通してどれ位光るかを決定します。 結果として、GD はその点に存在する色を描画色に自動的に混合し、 その結果を画像に保存します。できたピクセルは非透過になります。 非混合モード (non-blending mode) では、 描画色はそのアルファチャンネル情報とともにそのままコピーされ、 対象となるピクセルがそれに置きかえられます。 混合モードはパレット画像では利用できません。 =begin comment Pass a value of 1 for blending mode, and 0 for non-blending mode. =end comment 混合モードにするには 1 を、非混合モードにするには 0 を与えます。 =item B<$image-EsaveAlpha($saveAlpha)> =begin comment By default, GD (libgd 2.0.2 and above) does not attempt to save full alpha channel information (as opposed to single-color transparency) when saving PNG images. (PNG is currently the only output format supported by gd which can accommodate alpa channel information.) This saves space in the output file. If you wish to create an image with alpha channel information for use with tools that support it, call C to turn on saving of such information, and call C to turn off alpha blending within the library so that alpha channel information is actually stored in the image rather than being composited immediately at the time that drawing functions are invoked. =end comment デフォルトでは GD (libgd 2.0.2 以上) は、PNG 画像 (現在 gd でアルファチャンネル情報への対応をサポートする出力形式は PNG のみです) の保存時には (単一色透過に反する) アルファチャンネル情報を、完全に保存しようとはしませず、 出力ファイルに空白を保存します。 アルファチャンネル情報をサポートするツールで使うために その情報を持つ画像を生成したい場合は C を呼び出してその情報の保存を On にし、 そして C を呼び出して内部ライブラリの アルファ混合を off にします。 そうすれば、描画関数が呼び出されたときに直接混合される代わりに、 アルファチャンネル情報が実際に画像に保存されるようになります。 =back =head2 その他の画像処理メソッド =begin comment These are various utility methods that are useful in some circumstances. =end comment 以下の色々なメソッドは、状況によっては有用なものです。 =over 4 =item B<$image-Einterlaced([$flag])> =begin comment This method sets or queries the image's interlaced setting. Interlace produces a cool venetian blinds effect on certain viewers. Provide a true parameter to set the interlace attribute. Provide undef to disable it. Call the method without parameters to find out the current setting. =end comment このメソッドは画像のインターレースの設定をしたり、状態を調べます。 インターレースは実際の表示ソフト上で、素敵な板すだれ (ベネチア風ブラインド) のような効果を与えます。 引数に true を与えるとインターレース属性を設定し、 undef を与えると無効にします。 引数を与えずにこのメソッドを呼び出すと、現在の設定を調べます。 =item B<($width,$height) = $image-EgetBounds()> =begin comment This method will return a two-member list containing the width and height of the image. You query but not not change the size of the image once it's created. =end comment このメソッドは、画像の横幅と高さからなる 2 つの要素のリストを返します。 値を聞くことはできますが、画像が一度生成されるとそのサイズは変更しません。 =item B<$width = $image-Ewidth> =item B<$height = $image-Eheight> =begin comment Return the width and height of the image, respectively. =end comment これらはそれぞれ、画像の横幅と高さを返します。 =item B<$is_truecolor = $image-EisTrueColor()> =begin comment This method will return a boolean representing whether the image is true color or not. =end comment このメソッドは、画像が true color かそうでないかをブール値で返します。 =item B<$flag = $image1-Ecompare($image2)> =begin comment Compare two images and return a bitmap describing the differenes found, if any. The return value must be logically ANDed with one or more constants in order to determine the differences. The following constants are available: =end comment これは 2 つの画像を比較し、違いが見つかった場合は ビットフィールド形式でその違いを返します。 その違いを知るには、その返り値を一つ、あるいは複数の定数との 論理 AND を行う必要があります。 以下の定数が有効です: =begin comment GD_CMP_IMAGE The two images look different GD_CMP_NUM_COLORS The two images have different numbers of colors GD_CMP_COLOR The two images' palettes differ GD_CMP_SIZE_X The two images differ in the horizontal dimension GD_CMP_SIZE_Y The two images differ in the vertical dimension GD_CMP_TRANSPARENT The two images have different transparency GD_CMP_BACKGROUND The two images have different background colors GD_CMP_INTERLACE The two images differ in their interlace GD_CMP_TRUECOLOR The two images are not both true color =end comment GD_CMP_IMAGE 2 つの画像は違って見える GD_CMP_NUM_COLORS 2 つの画像は色数が違う GD_CMP_COLOR 2 つの画像はパレットが違う GD_CMP_SIZE_X 2 つの画像は水平サイズが違う GD_CMP_SIZE_Y 2 つの画像は垂直サイズが違う GD_CMP_TRANSPARENT 2 つの画像は透過情報が違う GD_CMP_BACKGROUND 2 つの画像は背景色が違う GD_CMP_INTERLACE 2 つの画像はインターレースが違う GD_CMP_TRUECOLOR 2 つの画像は少なくとも一方は true color でない =begin comment The most important of these is GD_CMP_IMAGE, which will tell you whether the two images will look different, ignoring differences in the order of colors in the color palette and other invisible changes. The constants are not imported by default, but must be imported individually or by importing the :cmp tag. Example: =end comment これらのうち最も重要なのは GD_CMP_IMAGE で、 これは 2 つの画像が違って見えることをレポートしますが、 カラーパレットの色の順番や、その他目に見えない違いは無視します。 この定数はデフォルトではインポートされていませんから、 個々にインポートするか、または :cmp タグを使って インポートする必要があります。例: =begin comment use GD qw(:DEFAULT :cmp); # get $image1 from somewhere # get $image2 from somewhere if ($image1->compare($image2) & GD_CMP_IMAGE) { warn "images differ!"; } =end comment use GD qw(:DEFAULT :cmp); # どこかから $image1 を持ってくる # どこかから $image2 を持ってくる if ($image1->compare($image2) & GD_CMP_IMAGE) { warn "画像が違ってる!"; } =item B<$image-Eclip($x1,$y1,$x2,$y2)> =item B<($x1,$y1,$x2,$y2) = $image-Eclip> =begin comment Set or get the clipping rectangle. When the clipping rectangle is set, all drawing will be clipped to occur within this rectangle. The clipping rectangle is initially set to be equal to the boundaries of the whole image. Change it by calling clip() with the coordinates of the new clipping rectangle. Calling clip() without any arguments will return the current clipping rectangle. =end comment これは長方形へのクリッピングを設定、あるいは取得します。 長方形へのクリッピングが設定されると、 全ての描画はこの長方形内に収まるようにクリッピングされます。 クリッピング長方形の初期設定は、画像全体の境界になっています。 新たなクリッピング長方形の座標を clip() に与えて呼び出すことで これが変更されます。 引数を与えずに clip() を呼び出すと、現在のクリッピング長方形を返します。 =item B<$flag = $image-EboundsSafe($x,$y)> =begin comment The boundsSafe() method will return true if the point indicated by ($x,$y) is within the clipping rectangle, or false if it is not. If the clipping rectangle has not been set, then it will return true if the point lies within the image boundaries. =end comment メソッド boundsSafe() は、($x,$y) で示された点が クリッピング長方形内にあれば true を、そうでなければ false を返します。 クリッピング長方形が設定されていなければ、 点が画像の領域内にあれば true を返します。 =back =head1 多角形 =begin comment A few primitive polygon creation and manipulation methods are provided. They aren't part of the Gd library, but I thought they might be handy to have around (they're borrowed from my qd.pl Quickdraw library). Also see L. =end comment いくつかの基本的な多角形の生成や操作のためのメソッドが提供されています。 これらは Gd ライブラリの一部ではありませんが、 経験的に言って便利だろうと思います (これらは、私の gd.pl Quickdraw ライブラリから借りてきたものです)。 L も参照してください。 =over 3 =item B<$poly = GD::Polygon-Enew> =begin comment Create an empty polygon with no vertices. =end comment これは、頂点を持たない空の多角形を作ります。 $poly = new GD::Polygon; =item B<$poly-EaddPt($x,$y)> =begin comment Add point (x,y) to the polygon. =end comment これは、多角形に頂点 (x,y) を追加します。 $poly->addPt(0,0); $poly->addPt(0,50); $poly->addPt(25,25); $myImage->fillPoly($poly,$blue); =item B<($x,$y) = $poly-EgetPt($index)> =begin comment Retrieve the point at the specified vertex. =end comment これは、指定した頂点の座標を返します。 ($x,$y) = $poly->getPt(2); =item B<$poly-EsetPt($index,$x,$y)> =begin comment Change the value of an already existing vertex. It is an error to set a vertex that isn't already defined. =end comment これは、既に存在する頂点の座標値を変更します。 その頂点が定義されていない場合、頂点の設定はエラーとなります。 $poly->setPt(2,100,100); =item B<($x,$y) = $poly-EdeletePt($index)> =begin comment Delete the specified vertex, returning its value. =end comment これは、指定された頂点を削除し、その座標を返します。 ($x,$y) = $poly->deletePt(1); =item B<$poly-EtoPt($dx,$dy)> =begin comment Draw from current vertex to a new vertex, using relative (dx,dy) coordinates. If this is the first point, act like addPt(). =end comment これは、現在の頂点から新しい頂点を、 相対的な座標 (dx,dy) を使って描画します。 これが最初の点である場合、addPt() と同様の動作をします。 $poly->addPt(0,0); $poly->toPt(0,50); $poly->toPt(25,-25); $myImage->fillPoly($poly,$blue); =item B<$vertex_count = $poly-Elength> =begin comment Return the number of vertices in the polygon. =end comment これは、多角形の頂点数を返します。 $points = $poly->length; =item B<@vertices = $poly-Evertices> =begin comment Return a list of all the verticies in the polygon object. Each member of the list is a reference to an (x,y) array. =end comment これは、多角形オブジェクト内の全ての頂点からなるリストを返します。 リストの個々の要素は (x,y) の配列への参照です。 @vertices = $poly->vertices; foreach $v (@vertices) print join(",",@$v),"\n"; } =item B<@rect = $poly-Ebounds> =begin comment Return the smallest rectangle that completely encloses the polygon. The return value is an array containing the (left,top,right,bottom) of the rectangle. =end comment これは、多角形全体が入る最も小さい長方形 (bounding box) を返します。 返り値は、その長方形の (left,top,right,bottom) ((左, 上, 右, 下)) の座標からなる配列です。 ($left,$top,$right,$bottom) = $poly->bounds; =item B<$poly-Eoffset($dx,$dy)> =begin comment Offset all the vertices of the polygon by the specified horizontal (dx) and vertical (dy) amounts. Positive numbers move the polygon down and to the right. =end comment これは、多角形の全ての頂点を指定した水平値 (dx) と垂直値 (dy) だけ 平行移動します。正の数を与えると、多角形は右、下へ移動します。 $poly->offset(10,30); =item B<$poly-Emap($srcL,$srcT,$srcR,$srcB,$destL,$dstT,$dstR,$dstB)> =begin comment Map the polygon from a source rectangle to an equivalent position in a destination rectangle, moving it and resizing it as necessary. See polys.pl for an example of how this works. Both the source and destination rectangles are given in (left,top,right,bottom) coordinates. For convenience, you can use the polygon's own bounding box as the source rectangle. =end comment これは、元の長方形から、移動先の長方形の同等な位置へ、 必要ならば移動とサイズの変更をして写像します。 これがどのように動作するかの例については、polys.pl を参照してください。 元の長方形と移動先の長方形は (左, 上, 右, 下) の座標で与えます。 元の長方形として多角形の bounding box を使うと便利でしょう。 # 高ーい多角形を作る $poly->map($poly->bounds,0,0,50,200); =item B<$poly-Escale($sx,$sy)> =begin comment Scale each vertex of the polygon by the X and Y factors indicated by sx and sy. For example scale(2,2) will make the polygon twice as large. For best results, move the center of the polygon to position (0,0) before you scale, then move it back to its previous position. =end comment これは、多角形の個々の頂点を sx,sy で示される値を X 方向 Y 方向の倍数として拡大縮小します。 例えば scale(2,2) は多角形を 2 倍に拡大します。 いい結果を得るためには、 拡大縮小の前に多角形の中心を (0,0) に移動しておいて、 終わった後でまた元の位置に戻すといいでしょう。 =item B<$poly-Etransform($sx,$rx,$sy,$ry,$tx,$ty)> =begin comment Run each vertex of the polygon through a transformation matrix, where sx and sy are the X and Y scaling factors, rx and ry are the X and Y rotation factors, and tx and ty are X and Y offsets. See the Adobe PostScript Reference, page 154 for a full explanation, or experiment. =end comment これは、多角形の個々の頂点に変換行列による変換を行います。 sx, sy は X, Y 方向の拡大倍率、rx, ry は X, Y 方向の回転率、 tx, ty は X, Y 方向の平行移動値です。 これらの詳細は、Adobe PostScript リファレンスマニュアルの 154 ページを参照するか、実験してみてください。 =back =head2 GD::Polyline =begin comment Please see L for information on creating open polygons and splines. =end comment 折れ線やスプライン曲線の作成に関する情報については、 L を参照してください。 =head1 フォントユーティリティ =begin comment The libgd library (used by the Perl GD library) has built-in support for about half a dozen fonts, which were converted from public-domain X Windows fonts. For more fonts, compile libgd with TrueType support and use the stringFT() call. =end comment (Perl の GD ライブラリが使用する) libgd ライブラリは、 半ダース程の組込みフォントをサポートしていますが、 これらは public-domain な X11 フォントから変換したものです。 さらにフォントを使いたい場合、libgd を TrueType をサポートするように コンパイルし、stringFT() 呼び出しを使ってください。 =begin comment If you wish to add more built-in fonts, the directory bdf_scripts contains two contributed utilities that may help you convert X-Windows BDF-format fonts into the format that libgd uses internally. However these scripts were written for earlier versions of GD which included its own mini-gd library. These scripts will have to be adapted for use with libgd, and the libgd library itself will have to be recompiled and linked! Please do not contact me for help with these scripts: they are unsupported. =end comment 組込みフォントを追加したい場合、 bdf_scripts ディレクトリに 2 つの寄与されたユーティリティがあります。 それらは X11 BDF 形式のフォントを、ibgd が内部で使用する形式に 変換するための手助けになるでしょう。 しかし、それらのスクリプトは、それ自身が小さい gd ライブラリを持っていた 以前の版の GD 用に書かれていますから、 libgd を使うように改良する必要がありますし、 libgd ライブラリ自身も再コンパイルしてリンクする必要があります。 これらのスクリプトに関しては私に連絡しないでください。 これらはサポートされていません。 =begin comment Each of these fonts is available both as an imported global (e.g. B) and as a package method (e.g. BSmall>). =end comment これらのフォントのそれぞれはインポートされた大域変数として有効で (例えば B)、パッケージのメソッドとしても有効 (例えば BSmall>) です。 =over 5 =item B =item BSmall> =begin comment This is the basic small font, "borrowed" from a well known public domain 6x12 font. =end comment これは小さい (small) フォントで、よく知られた public domain の 6x12 フォントから "借りてきた" ものです。 =item B =item BLarge> =begin comment This is the basic large font, "borrowed" from a well known public domain 8x16 font. =end comment これは基本の大きな (large) フォントで、よく知られた public domain の 8x16 フォントから "借りてきた" ものです。 =item B =item BMediumBold> =begin comment This is a bold font intermediate in size between the small and large fonts, borrowed from a public domain 7x13 font; =end comment これは small と large の中間のサイズの太字 (bold) フォントで、 public domain の 7x13 フォントから借りてきたものです。 =item B =item BTiny> =begin comment This is a tiny, almost unreadable font, 5x8 pixels wide. =end comment これはちっちゃくてほとんど見えないフォントで、 5x8 ピクセルの大きさです。 =item B =item BGiant> =begin comment This is a 9x15 bold font converted by Jan Pazdziora from a sans serif X11 font. =end comment これは 9x15 の太字 (bold) フォントで、Jan Pazdziora が X11 の sans serif フォントから変換したものです。 =item B<$font-Enchars> =begin comment This returns the number of characters in the font. =end comment これは、フォント内の文字の個数を返します。 print "The large font contains ",gdLargeFont->nchars," characters\n"; =item B<$font-Eoffset> =begin comment This returns the ASCII value of the first character in the font =end comment これは、フォント内の最初の文字の ASCII 値を返します。 =item B<$width = $font-Ewidth> =item B<$height = $font-Eheight> =item C =begin comment These return the width and height of the font. =end comment これは、フォントの幅と高さを返します。 ($w,$h) = (gdLargeFont->width,gdLargeFont->height); =back =head1 gd の C 言語版を取得するには =begin comment libgd, the C-language version of gd, can be obtained at URL http://www.boutell.com/gd/. Directions for installing and using it can be found at that site. Please do not contact me for help with libgd. =end comment C 言語版の gd である libgd は URL http://www.boutell.com/gd/ から取得できます。 インストールと利用の説明書はそのサイトに見つかります。 libgd に関しては私に連絡しないでください。 =head1 著者 =begin comment The GD.pm interface is copyright 1995-2000, Lincoln D. Stein. It is distributed under the same terms as Perl itself. See the "Artistic License" in the Perl source code distribution for licensing terms. =end comment GD.pm インターフェースは、1995-2000 年に Lincoln D. Stein が著作権を持っています。これは Perl と同じ条件の下で配布されます。 ライセンス条項に関しては、Perl のソースコード配布物に含まれる "Artistic License" を参照してください。 (訳注: この日本語訳は Shigeharu TAKENO に よります。) =begin comment The latest versions of GD.pm are available at =end comment GD.pm の最新版は以下にあります。 http://stein.cshl.org/WWW/software/GD =begin comment =head1 SEE ALSO =end comment =head1 関連項目 L, L, L, L =cut