とりあえず、大雑把に使い方も書いてみました。
ソースの順番に簡単なコメントを付けただけですが、間違いの訂正をして頂け
るでしょうか? その後でもう少し詳しい物を書こうと思います。
===== GD 拡張モジュールの使い方 =====
im = GD::Image.new(x_size, y_size) # 新規イメージ
im = GD::Image.newFromGif(gif_file_name) # gif ファイルから読み込む
im = GD::Image.newFronXbm(xbm_file_name) # xbm ファイルから読み込む
im = GD::Image.newFromGd(gd_file_name) # gd ファイルから読み込む
# もちろん、どれか1つにするか、別オブジェクトにしなければなりません。
im.destroy # イメージ破棄
color = im.colorAllocate(r, g, b) # その色を割り当てる
im.colorDeallocate(color) # その色の割り当て取消
color = im.colorClosest(r, g, b) # その色の割り当て保留
color = im.colorExact(r, g, b) # 既存の色から割り当てる
# 慎重な色割り当ての仕方はこんな感じかな。
color = im.colorExact(r, g, b) or
im.colorAllocate(r, g, b) or
im.colorClosest(r, g, b)
# と思ったら、nil ではなく -1 を返すので、これではだめなんですね。
im.colorsTotal # 全使用色数
color_name = im.getPixel(x, y) # そのポイントの色
im.rgb(color) # カラーテーブル --> RGB
im.trasparent(color) # その色を透明にする
im.setBrush(brush) # 筆の選択
blush = GD::Image.newFromGif(burush_file)
GD::Styled # (破)線
im.setStyle(color, color, ...) # (破)線のスタイルを定義
GD::Brushed # 筆
GD::StyledBrushed # 筆と(破)線
# 紅白線は、こんな感じ。
im.setStyle(red, white)
im.line(0, 0, 100, 0, GD::Styled)
im.setTile(tile) # 塗潰しのパターンの選択
tile = GD::Image.newFromGif(tile_file)
GD::Tiled # 塗潰しのパターン
GD::Transparent # 透明色
im.setPixel(x, y, color) # 1ピクセルの色変更
im.line(x1, y1, x2, y2, color) # 線を引く
im.dashedLine(x1, y1, x2, y2, color) # (破)線を引く
im.rectangle(x1, y1, x2, y2, color) # 長方形を描く
im.filledRectangle(x1, y1, x2, y2, color) # 中を塗潰した長方形を描く
im.polygon(polygon, color) # 多角形を描く
im.filledPolygon(polygon, color) # 中を塗潰した多角形を描く
# polygon は後述の Polygon オブジェクト。
im.arc(cx, cy, width, heihgt, start, end, color) # 円弧を描く
im.fill(x, y, color_name) # 塗潰す
im.fillToBorder(x, y, border_color, fill_color) # 縁線内を塗潰す
im.copy(im, x, y, sx, sy, sw, sh) # イメージを張り付ける
# もちろん im は別の Image オブジェクトでも良い。
# x, y の位置に、sx, sy, sw, sh の部分が張り付けられる。
im.copyResized(im, x, y, sx, sy, w, h, sw, sh) # リサイズして張り付ける
# x, y, w, h の範囲に sx, sy, sw, sh の範囲が張り付けられる。
im.string(font, x, y, string, color) # 文字列を書く
# font は後述の font オブジェクト。
im.stringUp(font, x, y, string, color) # 縦方向に文字列を書く
# 縦書きではない。単に90度回転した方向に書かれて行く。
im.char(font, x, y, string, color) # 文字を書く
im.charUP(font, x, y, string, color) # 縦方向に文字を書く
im.interlace # インターレースの状態
im.interlace = TRUE # インターレースにする
x_size, y_size = im.bounds # イメージの大きさ
x_size = im.width # イメージの横の大きさ
y_size = im.height # イメージの縦の大きさ
im.gif(OUT) # gif 形式での出力
im.gd(OUT) # gd 形式での出力
polygon = GD::Polygon.new # 多角形オブジェクトの生成
polygon.addPt(x, y) # 点(角) x, y を追加
x, y = polygon.getPt(n) # n 番目の点の位置
polygon.setPt(n, x, y) # n 番目の点を x, y に変更
polygon.deletePt(n) # n 番目の点を削除
all_points = polygon.length # 点の総数
xs = polygon.vertices # 各点の x 位置?
x1, y1, x2, y2 = polygon.bounds # 多角形の範囲
polygon.offset(vx, vy) # 多角形全体の移動
polygon.map(x1, y1, x2, y2) # 多角形全体のリサイズ
polygon.map(sx1, sy1, sx2, sy2, x1, y1, x2, y2) # 多角形の一部のリサイズ
# sx1, sy1, sx2, sy2 の範囲を x1, y1, x2, y2 の範囲に。(だと思うのですが)
font = GD::Font.new(font_name) # フォントオブジェクトの生成
# font_name : "Giant", "Small", "Large", "Medium", "Medium", "Tiny"
characters = font.nchars # フォントの文字数
first_character_no = font.offset # 最初の有効な文字の番号?
width = font.width # フォントの幅
height = font.height # フォントの高さ
青山 和光 Wakou Aoyama <pxn11625 / niftyserve.or.jp>