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 ($image, 20, 20, 200, 150, IMG_COLOR_TILED);
imagefilledellipse($image, 110, 200, 180, 80, IMG_COLOR_TILED);
?>
<?php
Header("Content-type: image/jpeg");
$height = 260;
$width = 220;
$image = imagecreate($width, $height);
$back = imagecolorallocate($image, 255,255,255);
$tile = imagecreatefromgif("http://eclecticdjs.com/mike/tutorials/dungeon/images/roughgranitebricks_04.gif");
imagesettile ($image, $tile);
imagefilledrectangle ($image, 20, 20, 200, 150, IMG_COLOR_TILED);
imagefilledellipse($image, 110, 200, 180, 80, IMG_COLOR_TILED);
imagegif($image);
imagedestroy($image);
imagedestroy($tile);
?>
|
|
|