image editing
|translucent text
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.
full source of translucent text [ line 1 - 19 ] | download translucent text
| 1 | <?php |
| 2 | function imagettftexttransparent (& $im ,$size ,$angle ,$x ,$y ,& $col ,$fontfile ,$text ,$pct ) |
| 3 | { |
| 4 | $im_w = imagesx ($im ); // Get the image width |
| 5 | $im_h = imagesy ($im ); // Get the image height |
| 6 | $new = imagecreate ($im_w ,$im_h ); // Create a buffer |
| 7 | imagesetpixel ($im ,$im_w -1,0,$col ); // Set a pixel down, so we can easily get the color |
| 8 | $index = imagecolorat ($im ,$im_w -1,0); // Get the color at that pixel |
| 9 | $rgb = imagecolorsforindex ($im ,$index ); // Get the index of that color |
| 10 | $r = $rgb ["red" ]; // Get the red value |
| 11 | $g = $rgb ["green" ]; // Get the green value |
| 12 | $b = $rgb ["blue" ]; // Get the blue value |
| 13 | $color = imagecolorallocate ($new ,$r ,$g ,$b ); // Allocate this color on the buffer |
| 14 | $copy = imagecopy ($new ,$im ,0,0,0,0,$im_w ,$im_h ); // Copy the old image onto the buffer |
| 15 | $text = imagettftext ($new ,$size ,$angle ,$x ,$y ,$color ,$fontfile ,$text ); // Draw the text |
| 16 | $merge = imagecopymerge ($im ,$new ,0,0,0,0,$im_w ,$im_h ,$pct ); // Copy the buffer back onto the original image |
| 17 | imagedestroy ($new ); // Destroy the buffer |
| 18 | } |
| 19 | ?> |
3 hits by 3 users in the last 30 minutes.