imagesettile

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

imagesettileModifica la imagen utilizada para el mosaico

Descripción

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

imagesettile() reemplaza la imagen de pavimentación actual por la imagen tile, a utilizar en todos los rellenos (como con las funciones imagefill() y imagefilledpolygon()) durante los rellenos con la opción IMG_COLOR_TILED.

Una imagen de mosaico es una imagen utilizada para rellenar una zona, de manera repetitiva. Cualquier imagen GD puede servir como imagen de relleno. El uso de la transparencia (gestionada con la función imagecolortransparent()) permite que ciertas zonas aparezcan a través del mosaico.

Precaución

No hay nada que hacer cuando se ha terminado con un pincel, pero si se destruye la imagen del pincel (o se deja que PHP lo destruya), ya no DEBE utilizarse la opción IMG_COLOR_TILED de las funciones imagefill() y imagefilledpolygon(), antes de crear un nuevo pincel.

Parámetros

image

Un objeto GdImage, retornado por una de las funciones de creación de imágenes, como imagecreatetruecolor().

tile

El objeto de la imagen a utilizar como mosaico.

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Historial de cambios

Versión Descripción
8.0.0 image y tile ahora esperan instancias de GdImage ; anteriormente, se esperaban resources.

Ejemplos

Ejemplo #1 Ejemplo con imagesettile()

<?php
// Carga de una imagen externa
$zend = imagecreatefromgif('./zend.gif');

// Creación de una imagen de 200x200 píxeles
$im = imagecreatetruecolor(200, 200);

// Definición del mosaico
imagesettile($im, $zend);

// Repetición de la imagen
imagefilledrectangle($im, 0, 0, 199, 199, IMG_COLOR_TILED);

// Visualización en el navegador
header('Content-Type: image/png');

imagepng($im);
?>

Resultado del ejemplo anterior es similar a :

Visualización del ejemplo: imagesettile()

add a note

User Contributed Notes 2 notes

up
4
aquilo at xtram dot net
21 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
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.
To Top