PHP 8.3.4 Released!

imagesettile

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

imagesettile塗りつぶし用のイメージを設定する

説明

imagesettile(GdImage $image, GdImage $tile): bool

imagesettile() は、特別な色 IMG_COLOR_TILED を指定して塗りつぶされた場合に、 (imagefill()imagefilledpolygon() のような) 領域塗りつぶし関数で使用されるタイルイメージを設定します。

タイルは、領域を塗りつぶすために繰り返し使用されるイメージです。 全ての GD イメージをタイルとして使用可能で、 imagecolortransparent() でタイルの透過色 ID を設定することにより、 その一部から下の部分が透けて見えるようなタイルを作成することが可能です。

警告

タイルの使用が終った際には、特別な処理は不要ですが、 タイルイメージを破棄する(もしくは、PHPに破棄させる)場合には、 新たにタイルイメージを設定するまでは、色 IMG_COLOR_TILED を使用してはいけません。

パラメータ

image

imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。

tile

タイルとして使用する画像オブジェクト。

戻り値

成功した場合に true を、失敗した場合に false を返します。

変更履歴

バージョン 説明
8.0.0 imagetile は、 GdImage クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、 resource を期待していました。

例1 imagesettile() の例

<?php
// 外部の画像を読み込みます
$zend = imagecreatefromgif('./zend.gif');

// 200x200 の画像を作成します
$im = imagecreatetruecolor(200, 200);

// タイルを設定します
imagesettile($im, $zend);

// 画像の繰り返しを設定します
imagefilledrectangle($im, 0, 0, 199, 199, IMG_COLOR_TILED);

// 画像をブラウザに出力します
header('Content-Type: image/png');

imagepng($im);
imagedestroy($im);
imagedestroy($zend);
?>

上の例の出力は、 たとえば以下のようになります。

出力例 : imagesettile()

add a note

User Contributed Notes 2 notes

up
4
aquilo at xtram dot net
19 years ago
There is very little information about this function so I thought I'd add a few notes I found while trying to get this

working.

First make sure your version of PHP is above 4.3.2 I spent an hour searching goggles 13000+ mirrors of this same page and

finally found the info I needed at AltaVista, there is a bug in PHP 4.3.2 that makes this none functional.

if your creating the base image you need to create it with imageCreateTrueColor() if your using a PNG with transparency, I

found even nullifying the PNG's transparency with GD doesn't work. the tiling PNG has to be created without transparency to work with imageCreate(). but from what I've seen imageCreateFromXXX() can use transparent and nonetransparent PNG's.

here is an example.
<?php
$diagramWidth
= 300;
$diagramHeight = 50;

$image = imageCreateTrueColor ($diagramWidth, $diagramHeight);
$imagebg = imageCreateFromPNG ('tile.png'); // transparent PNG

imageSetTile ($image, $imagebg);
imageFilledRectangle ($image, 0, 0, $diagramWidth, $diagramHeight, IMG_COLOR_TILED);

$textcolor1 = imageColorAllocate ($image, 80, 80, 80);
$textcolor2 = imageColorAllocate ($image, 255, 255, 255);

imageString ($image, 3, 10, 20, 'Transparent PNG Tile Test...', $textcolor1);
imageString ($image, 3, 9, 19, 'Transparent PNG Tile Test...', $textcolor2);

Header("Content-type: image/png");
imagePNG ($image);

imagedestroy ($image);
imagedestroy ($imagebg);
?>

hope this helps someone else!
Aquilo
up
0
onion at ooer dot com
18 years ago
If you're using a tile image that has some form of transparency you'll need to make sure your destination image is set to use alpha blending. By default it will be, but if for any reason you've changed it you'll need to do:

imagealphablending($image,true);

before any operation using IMG_COLOR_TILED.
To Top