imagesettile
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
imagesettile — 设置要填充的平铺图像
说明
当使用特殊颜色 IMG_COLOR_TILED
时,imagesettile()
设置所有区域填充函数(比如 imagefill()
和 imagefilledpolygon())要使用的平铺图像。
平铺是指使用重复模式填充区域的图像。任何 GD 图像都可以用于平铺,并且通过使用 imagecolortransparent() 来设定平铺图像的透明颜色索引,可以创建允许底层区域的某些部分透过的平铺。
警告
平铺完成后不需要采取什么特殊动作,但如果要销毁平铺图像(或让 PHP 销毁),不能使用
IMG_COLOR_TILED
颜色,除非设置了新的平铺图像。
示例
示例 #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);
?>
以上示例的输出类似于:

+添加备注
用户贡献的备注 2 notes
aquilo at xtram dot net ¶
20 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
onion at ooer dot com ¶
19 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.
备份地址:http://www.lvesu.com/blog/php/function.imagesettile.php