DJ Mike's Tutorials: PHP

< ^ >

Tiling Images

Note: PHP 4.3.2 has a bug that disabled imagesettile().

As well as filling a shape with a color, you can fill it with a tiled image. To start a tile fill, you use the function imagesettile(). imagesettile works someting like define() in that it defines a constant but instead of the constant being a number or string, the constant named IMG_COLOR_TILED that is a special color resource

imagesettile() has two arguments; both of them image resources. The first is the image resource that you are tiling on to and the second is the image resource to be tiled.



<?
imagesettile
($main_image$tile_image, );
?>


When used, imagesettile() creates the constant IMG_COLOR_TILED that can be used in place of a normal color resource in the following functions:

imagefill()
imagefilltoborder()
imagefilledellipse()
imagefilledpolygon()
imagefilledrectangle()

For the image below, I created a white JPEG for a background, then added this block of code to create an image resource and set it as a tile:

<?
$tile 
imagecreatefromgif("http://eclecticdjs.com/mike/tutorials/dungeon/images/roughgranitebricks_04.gif"); 

imagesettile ($image$tile);
?>



Next, I draw a filled rectangle and ellipse but where I'ld normally use a variable for a color resource, I use the constant, IMG_COLOR_TILED

<?
imagefilledrectangle 
($image2020200150IMG_COLOR_TILED); 

imagefilledellipse($image11020018080IMG_COLOR_TILED);
?>



<?php 
Header
("Content-type: image/jpeg"); 
$height 260
$width 220
$image imagecreate($width$height); 
$back imagecolorallocate($image255,255,255); 

$tile imagecreatefromgif("http://eclecticdjs.com/mike/tutorials/dungeon/images/roughgranitebricks_04.gif"); 

imagesettile ($image$tile); 

imagefilledrectangle ($image2020200150IMG_COLOR_TILED); 

imagefilledellipse($image11020018080IMG_COLOR_TILED); 

imagegif($image); 
imagedestroy($image); 
imagedestroy($tile); 
?> 


< ^ >


Created by DJ Mike from Santa Barbara

DJ Mike


Dance Away Santa Barbara's Home Page
<a href="http://www.statcounter.com/" target="_blank"> <img src="http://c5.statcounter.com/counter.php?sc_project=1321035&java=0&security=da2193dc" alt="counter free hit invisible" border="0" /></a>