Textures
<?php
function imagettftexttexture(&$im,&$textureim,$size,$angle,$x,$y,$fontfile,$text) {
$width = imagesx($im); // Get the width of the image
$height = imagesy($im); // Get the height of the image
$buffer = imagecreate($width,$height); // Create the buffer image
$tile_w = imagesx($textureim); // Get the width of the texture image
$tile_h = imagesy($textureim); // Get the height of the texture image
$fits_x = (int)($im_w/$tile_w); // Find out how many times it fits horizontally
$fits_y = (int)($im_h/$tile_h); // Find out how many times it fits vertically
for ($i=0;$i<=$fits_x;$i++) { // Loop through every time (and another, for extra space) it fits horizontally
$x = (int)($tile_w*$i); // Change the X location based on where in the loop it is
for ($i2=0;$i2<=$fits_y;$i2++) { // Loop through every time it fits vertically
$y = (int)($tile_h*$i2); // Change the Y location
$copy = imagecopy($im,$textureim,$x,$y,0,0,$tile_w,$tile_h); // Copy the image to the X,Y location
}
}
$pink = imagecolorclosest($im,255,0,255); // Create magic pink, a color commonly used for masks
$trans = imagecolortransparent($im,$pink); // Make magic pink the transparent color
imagettftext($im,$size,$angle,$x,$y,-$pink,$fontfile,$text); // Draw text over magic pink without aliasing
imagecopy($buffer,$im,0,0,0,0,$width,$height); // Copy the main image onto the buffer
imagecopy($im,$buffer,0,0,0,0,$width,$height); // Copy the buffer back onto the main image
imagedestroy($buffer); // Destroy the buffer
}
?>
imagettftexttexture
($img,$texture,40,0,10,50,”arial.ttf”,”AaBbCcDd”) where $texture
contains a brick tile, we can create this image: