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.
imagesettile
(PHP 4 >= 4.0.6, PHP 5)
imagesettile — Establecer la imagen de tesela para rellenos
Descripción
$image
, resource $tile
)
imagesettile() establece la imagen de tesela para usarse
con todas las funciones de relleno de regiones (como imagefill()
y imagefilledpolygon()) cuando se rellena con el color
especial IMG_COLOR_TILED.
Una tesela es una imagen usada para rellenar un área con un patrón repetido. Cualquier imagen GD se puede usar como una tesela, y estableciendo el índice de color transparente de la imagen de tesela con imagecolortransparent(), se puede hacer que una tesela permita que ciertas partes del área de la capa inferior brillen a través de la imagen.
Nota:
No se necesita tomar acciones especiales cuando se ha dejado de usar una tesela, pero si se destruye la imagen de tesela, ¡no se debe usar el color
IMG_COLOR_TILEDhasta que se haya establecido una nueva imagen de tesela!
Parámetros
-
image -
Un recurso image, es devuelto por una de las funciones de creación de imágenes, como imagecreatetruecolor().
-
tile -
El recurso de imagen que va a ser usado como una tesela.
Valores devueltos
Devuelve TRUE en caso de éxito o FALSE en caso de error.
Ejemplos
Ejemplo #1 Ejemplo de imagesettile()
<?php
// Cargar una imagen externa
$zend = imagecreatefromgif('./zend.gif');
// Crear una imagen de 200x200
$im = imagecreatetruecolor(200, 200);
// Establecer la tesela
imagesettile($im, $zend);
// Hacer que la imagen se repita
imagefilledrectangle($im, 0, 0, 199, 199, IMG_COLOR_TILED);
// Imprimir la imagen en el navegador
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
imagedestroy($zend);
?>
El resultado del ejemplo sería algo similar a:
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
