略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: imagesettile

2024-12-22

imagesettile

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

imagesettile设定用于填充的贴图

说明

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

imagesettile() 设定所有区域填充函数(例如 imagefill()imagefilledpolygon())在使用特殊颜色 IMG_COLOR_TILED 填充时所使用的贴图。

贴图是指用重复的样式来填充一块区域所使用的图像。任何 GD 图像都能用作贴图,并且通过使用 imagecolortransparent() 来设定贴图的透明色,贴图可以使底层的特定区域透上来。

注意:

使用完贴图后不需要采取什么特殊动作。但如果销毁了贴图,在设定一个新的贴图之前不能使用 IMG_COLOR_TILED

add a noteadd a note

User Contributed Notes 2 notes

up
3
aquilo at xtram dot net
18 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, 39, 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
16 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.

官方地址:https://www.php.net/manual/en/function.imagesettile.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3