akikidevel / gdimage
Requires
- php: >=5.4.0
- ext-gd: *
This package is not auto-updated.
Last update: 2025-08-03 09:27:04 UTC
README
$image = new akiki\gd\Image();
メソッドの説明には上の $image (インスタンス)を使います。
カラー要素は、255段階ではなく0.0〜1.0の正規化した値を使います。
角度は、0〜360(デグリー)を使います。
フィルター
- fGrayscale()
- fSepia()
- fNegate()
- fBrightness()
- fContrast()
- fColorize()
- fEdgedetect()
- fEmboss()
- fGaussianblur()
- fSelectiveblur()
- fMeanremoval()
- fSmooth()
- fPixelate()
描画合成
表示出力
色操作
図形描画
画像操作
new Imageインスタンスの生成
new akiki\gd\Image(); new akiki\gd\Image("FILE_PATH"); new akiki\gd\Image(WIDTH, HEIGTH);
void file(string $filepath)
ファイル読み込み(ファイルの拡張子でpng/jpg/gifを判断します。 コンストラクタで file()を呼び出しています。)
$image->file("test.png");
void create(int $width, int $height)
指定サイズのイメージを作成(コンストラクタで create()を呼び出しています。)
$image->create(200, 300); // 横200 縦300 の透明画像を作成
void clear($rOrgba = 0.0, $g = 0.0, $b = 0.0, $a = 0.0)
指定したカラーで画像を消去します。(指定値は、0〜1.0 A(アルファ)0.0で完全透明 1.0で不透明)
$image->clear(); // 透明な黒で消去 $image->clear(1.0, 1.0, 1.0, 1.0); // 白で消去 $rgba = (object) { "r" => 0.0, "g" => 0.0, "b" => 0.0, "a" => 0.0 }; $image->clear($rgba); // rgba objectを使ってクリアカラーの指定
object getSize()
画像のサイズを取得する(object)
$size = $image->getSize(); echo $size->width; // 横幅 echo $size->height;// 高さ
object getRect()
画像のサイズを取得する(object)
$rect = $image->getRect(); echo $rect->x; // 0 echo $rect->y; // 0 echo $rect->width; // 横幅 echo $rect->height;// 高さ
int packColor($rOrgba = 0.0, $g = 0.0, $b = 0.0, $a = 0.0)
指定したカラーをintにして返します。(指定値は、0〜1.0 A(アルファ)0.0で完全透明 1.0で不透明)
$image->packColor(); // 透明な黒 $image->packColor(1.0, 1,0, 1.0, 1.0); // 不透明な白 $rgba = (object) { "r" => 0.0, "g" => 0.0, "b" => 0.0, "a" => 0.0 }; $image->packColor($rgba); // rgba objectを使ってrgbaを指定(透明な黒)
void fGrayscale()
画像をグレースケール(白黒)にする
$image->fGrayscale();
void fSepia()
画像をセピア調にする (色相と彩度指定でもセピア調にすることもできます->xxxxx)
$image->fSepia();
void fNegate()
画像を色を反転
$image->fNegate();
void fBrightness($brightness = 0.0)
画像の輝度を変更($brightness (-1.0〜1.0))
$image->fBrightness(1.3);
void fContrast($contrast)
画像のコントラストを変更
$image->fContrast(20);
void fColorize($r = 0.0, $g = 0.0, $b = 0.0, $a = 1.0)
画像に指定カラーのフィルターをかける
$image->fColorize(0.5, 0.0, 0.0, 1.0); // 赤みかかった画像
void fEdgedetect()
画像のエッジを検出し画像のエッジを強調
$image->fEdgedetect();
void fEmboss()
画像にエンボス処理を行う
$image->fEmboss();
void fGaussianblur(int $n = 1)
画像をぼかす(ガウス分布で)($n 何回かけるかの指定で多くなるとよりぼけた画像になる)
$image->fGaussianblur(3);
void fSelectiveblur(int $n = 1)
画像をぼかす($n 何回かけるかの指定で多くなるとよりぼけた画像になる)
$image->fSelectiveblur(3);
void fMeanremoval(int $n = 1)
平均を除去しスケッチ風効果($n 回効果処理)
$image->fMeanremoval(3);
void fSmooth(float $weight)
画像を滑らかにする($weight 強さの指定)
$image->fSmooth(30);
void fPixelate(int $size, boolean $advanced = true)
画像にモザイクをかける($size モザイクサイズ)
$image->fPixelate(5);
void draw(Image $image, int $dx = 0, int $dy = 0)
画像に指定画像を指定位置へ描画する(コピー)
$image->draw($image2, 50, 0);
void drawRect(Image $image, object $srect, int $dx = 0, int $dy = 0, $pct = 1.0)
画像に指定画像の一部分を指定位置へ描画する(部分コピー)
$srect = $image2->getRect(); // $srect->x // $srect->y // $srect->width // $srect->height $image->drawRect($image2, $srect, 100, 10); $image->drawRect($image2, $srect, 100, 10, 0.5); // 半透明同士で合成
void disp()
ブラウザへ描画する(画像データのみの場合だけブラウザーに表示される)
$image->disp();
void save($file, $quality = 0.92)
ファイルへ画像を出力します(画像タイプは、拡張子で判定されます)
$image->save("test.png"); $image->save("test.jpg", 0.8); // $qualityは、jpgのみ使用されます
void dataUriScheme($mime = 'png', $quality = 0.92)
データuriスキームを得る
data:image/png;base64,XXXXX 形式文字列データを得る
$dataurischeme = $image->dataUriScheme('png'); --> tag img src=$dataurischemeの内容をここに(htmlに埋め込める)
Resource gdResource()
GDリソースオブジェクトを得る(PHP GDの関数を直接呼び出したい時に使用します。)
$gdresource = $image->gdResource();
object getRgba(int $x, int $y)
指定した位置の画像ピクセルカラーを得る(object:rgba (0.0〜1.0))
$rgba = $image->getRgba(0, 0); // $rgba->r (0.0〜1.0) // $rgba->g (0.0〜1.0) // $rgba->b (0.0〜1.0) // $rgba->a (0.0〜1.0 0.0で透明)
void xSV($xS = 1.0, $xV = 1.0)
画像の彩度明度に値を乗算 xS(彩度0.0〜) xV(明度0.0〜)
$image->xSV(1.3); // 彩度を1.3倍にする $image->xSV(1.0, 1.3); // 明度を1.3倍にする
void rotateHue(float $angle)
画像の色相を回す($angle 0~360)
$image->rotateHue(120);
void setHue(float $angle)
画像の色相を指定回転位置にする($angle 0~360)
$image->setHue(30);
void setSaturation(float $saturation)
画像の彩度を指定値にする($saturation 0.0〜1.0)
// 以下の2行でセピア調になる $image->setSaturation(0.45); $image->setHue(30);
void replaceColor($rgba, $torgba = null)
$rgbaのカラーと同じpixelを$torgbaのカラーに置き換える
// 画像 0,0 のカラーを取得して透明にして置き換える $rgba = $image->getRgba(); $torgba = $image->getRgba(); $torgba->a = 0.0; $image->replaceColor($rgba, $torgba);
void setShapeColor($rOrgb = 0.0, $g = 0.0, $b = 0.0, $a = 1.0)
shapeXXX() 図形を描くメソッドで使用するカラーを設定する
$image->setShapeColor(); // 不透明な黒 $image->setShapeColor(1.0, 1,0, 1.0, 1.0); // 不透明な白 $rgba = (object) { "r" => 0.0, "g" => 0.0, "b" => 0.0, "a" => 0.5 }; $image->packColor($rgba); // rgba objectを使ってrgbaを指定(半透明な黒)
void shapeRect(boolean $fill, $rectOx, $y = 0, $ex = 0, $ey = 0)
画像に矩形を描画する
$image->shapeRect(0, 10, 10, 100, 50); // 塗りつぶし無し横長矩形 $rect = $image->getRect(); $rect->width /= 2; $rect->height /= 2; $image->shapeRect(1, $rect); // 塗りつぶし画像左上に画像の1/4の矩形
void shapeLine($x, $y, $ex, $ey)
画像に線を描画する $image->shapeLine(0, 0, 100, 100);
void shapeEllipse($fill, $rectOcx, $cy = 0, $width = 0, $height = 0)
画像に楕円を描画する
// 中心座標100,100 に横幅50 高さ30 の塗りつぶした楕円を描画 $image->shapeEllipse(1, 100, 100, 50, 30); // object rectを使った描画 $rect = $image->getRect(); $rect->x = 200; $rect->y = 200; $rect->width = 50; $rect->height = 30; $image->shapeEllipse(0, $rect);
void shapeRegularPolygon($fill, $vertexNum, $cx, $cy, $r, $rotateDeg = 0)
指定頂点数の正多角形を描画する(最初の頂点が中心座標の上になります)
// 中心座標200,200 半径50の正六角形を塗りつぶしで描画 $image->shapeRegularPolygon(1, 6, 200, 200, 50); // 中心座標200,200 半径50の正六角形を30度回転して枠線を描画 $image->shapeRegularPolygon(0, 6, 200, 200, 50, 30);
hsv rgb2hsv($rOcol, $g = 0, $b = 0)
指定したrgbカラーのhsv objectを得る(rgb (0.0〜1.0))
$hsv = $image->rgb2hsv(1.0, 0,0, 0,0); // 赤 // $hsv->h // Hue:色相 (0〜360) // $hsv->s // Saturation:彩度 (0.0〜1.0) // $hsv->v // Value:明度 (0.0〜1.0)
void flipV()
画像を上下反転
$image->flipV();
void flipH()
画像を左右反転
$image->flipH();
void clean()
画像の透明になっている部分を黒の透明にする(pngの圧縮効率が上がる等)
$image->clean();
Image scale(float $scale)
指定スケール(1.0が等倍)値でイメージの拡大縮小をして、新しく生成されたImageインスタンスを返します。
$scale_image = $image->scale(2.0); // 2倍に拡大した画像
Image rotate(float $angle)
指定ANGLE(デグリー0〜360)回転して、新しく生成されたImageインスタンスを返します。
$rotate_image = $image->rotate(45); // 45°回転した画像
Image diffImage(Image $image2, object $rect = null)
画像と指定した画像の差分画像を得る(違う部分を$image2から抜き出し同じ部分をalpha透明とした画像)
// rectを指定すると差分が生じた矩形情報が得られる $rect = $image->getRect(); $diffimage = $image->diffImage($image2, $rect);
Image shapeOutlinesImage()
アルファ抜き画像の輪郭画像を得る
$outlinesimage = $image->shapeOutlinesImage();