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 "translucent text"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

image editing - translucent text was created/last modified on Mon 06 Oct 2003 7:09 PM

Translucent Text

Translucent text is not as simple as outlining or shadowing, but it's not particularly hard.  A translucent image is just something partially invisible, or clear.  This is done by drawing the image onto a buffer, editing the buffer, and then merging the buffer back onto the original image.

<?php
function imagettftexttransparent (& $im ,$size ,$angle ,$x ,$y ,& $col ,$fontfile ,$text ,$pct )
{
    
$im_w = imagesx ($im ); // Get the image width
    
$im_h = imagesy ($im ); // Get the image height
    
$new = imagecreate ($im_w ,$im_h ); // Create a buffer
    
imagesetpixel ($im ,$im_w -1,0,$col ); // Set a pixel down, so we can easily get the color
    
$index = imagecolorat ($im ,$im_w -1,0); // Get the color at that pixel
    
$rgb = imagecolorsforindex ($im ,$index ); // Get the index of that color
    
$r = $rgb ["red" ]; // Get the red value
    
$g = $rgb ["green" ]; // Get the green value
    
$b = $rgb ["blue" ]; // Get the blue value
    
$color = imagecolorallocate ($new ,$r ,$g ,$b ); // Allocate this color on the buffer
    
$copy = imagecopy ($new ,$im ,0,0,0,0,$im_w ,$im_h ); // Copy the old image onto the buffer
    
$text = imagettftext ($new ,$size ,$angle ,$x ,$y ,$color ,$fontfile ,$text ); // Draw the text
    
$merge = imagecopymerge ($im ,$new ,0,0,0,0,$im_w ,$im_h ,$pct ); // Copy the buffer back onto the original image
    
imagedestroy ($new ); // Destroy the buffer
}
?>

learn more about some of the PHP functions used in this snippet: copy, file, for, function, imagecolorallocate, imagecolorat, imagecolorsforindex, imagecopy, imagecopymerge, imagecreate, imagedestroy, imagesetpixel, imagesx, imagesy, imagettftext, parent

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