PHP 8.3.4 Released!

imagesettile

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

imagesettileDefine a imagem de ladrilho para preenchimento

Descrição

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

imagesettile() define a imagem de ladrilho para ser usada por todas as funções de preenchimento de região (tal como imagefill() e imagefilledpolygon()) ao preencher com a cor especial IMG_COLOR_TILED.

O ladrilho é uma imagem usada para preencher uma área com um padrão repetido. Qualquer imagem GD pode ser usada como ladrilho, e ao definir o índice de cor transparente da imagem de ladrilho com imagecolortransparent(), permite-se que certas partes da área subjacente apareçam.

Cuidado

Não é necessário tomar ações especiais ao terminar de usar uma imagem de ladrilho, mas se ela for destruída, a cor IMG_COLOR_TILED não poderá ser usada até que uma nova imagem de ladrilho seja definida!

Parâmetros

image

Um objeto GdImage, retornado por uma das funções de criação de imagem, como imagecreatetruecolor().

tile

O objeto imagem a ser usado como ladrilho.

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Registro de Alterações

Versão Descrição
8.0.0 image e tile agora esperam instâncias GdImage; anteriormente, resources eram esperados.

Exemplos

Exemplo #1 Exemplo de imagesettile()

<?php
// Carrega uma imagem externa
$zend = imagecreatefromgif('./zend.gif');

// Cria uma imagem 200x200
$im = imagecreatetruecolor(200, 200);

// Define o ladrilho
imagesettile($im, $zend);

// Faz a imagem se repetir
imagefilledrectangle($im, 0, 0, 199, 199, IMG_COLOR_TILED);

// Mostra a imagem no navegador
header('Content-Type: image/png');

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

O exemplo acima produzirá algo semelhante a:

Saída do exemplo: 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