communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "image editing" - download "textures"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

image editing - textures was created/last modified on Mon 06 Oct 2003 7:08 PM

Textures

Textures are one of the hardest text effects possible.  This is due to the fact that you need to know how to use a mask to create the texture.

<?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
}
?>

learn more about some of the PHP functions used in this snippet: asin, copy, file, for, function, imagecolorclosest, imagecolortransparent, imagecopy, imagecreate, imagedestroy, imagesx, imagesy, imagettftext, parent, time

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari