View Single Post
  #2 (permalink)  
Old 12-03-2006, 04:28 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,237
Last Blog:
Passwords
Credits: 877
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John Send a message via MSN to John
Default

Here are two more scripts that take advantage of GD, I've posted these before but I figured i'll post them here to keep track of them.

Captcha Generator
PHP Code:
<?php
function RandomStringGenerator($length){
global 
$string;
    
$pattern "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
if(empty(
$length)){
    
$length "10";
    }
for(
$i=0$i<$length$i++){
    
$string .= $pattern{rand(0,61)};
    }

return 
$string;
}

function 
CaptchaGenerator(){
global 
$string;
RandomStringGenerator();
header("Content-type: image/png");
$im = @imagecreate(10050)
   or die(
"Cannot Initialize new GD image stream");
$background_color imagecolorallocate($im000);
$text_color imagecolorallocate($im25500);
imagestring($im1055,  $string$text_color);
imagepng($im);
imagedestroy($im);
}

CaptchaGenerator(); 
?>
Signature Rotator/Banner Rotator:

PHP Code:
<?php

$folder 
'./';

$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';

$img null;

if (
substr($folder,-1) != '/') {
   
$folder $folder.'/';
}

if (isset(
$_GET['img'])) {
   
$imageInfo pathinfo($_GET['img']);
   if (
       isset( 
$extListstrtolower$imageInfo['extension'] ) ] ) &&
       
file_exists$folder.$imageInfo['basename'] )
   ) {
       
$img $folder.$imageInfo['basename'];
   }
} else {
   
$fileList = array();
   
$handle opendir($folder);
   while ( 
false !== ( $file readdir($handle) ) ) {
       
$file_info pathinfo($file);
       if (
           isset( 
$extListstrtolower$file_info['extension'] ) ] )
       ) {
           
$fileList[] = $file;
       }
   }
   
closedir($handle);

   if (
count($fileList) > 0) {
       
$imageNumber time() % count($fileList);
       
$img $folder.$fileList[$imageNumber];
   }
}

if (
$img!=null) {
   
$imageInfo pathinfo($img);
   
$contentType 'Content-type: '.$extList$imageInfo['extension'] ];
   
header ($contentType);
   
readfile($img);
} else {
   if ( 
function_exists('imagecreate') ) {
       
header ("Content-type: image/png");
       
$im = @imagecreate (100100)
           or die (
"Cannot initialize new GD image stream");
       
$background_color imagecolorallocate ($im255255255);
       
$text_color imagecolorallocate ($im0,0,0);
       
imagestring ($im255,  "IMAGE ERROR"$text_color);
       
imagepng ($im);
       
imagedestroy($im);
   }
}

?>
To add a border to text:
PHP Code:
/**
 * Writes the given text with a border into the image using TrueType fonts.
 * @author John Ciacia < John@extreme-hq.com >
 * @param image An image resource.
 * @param size The font size.
 * @param angle The angle in degrees to rotate the text.
 * @param x Upper left corner of the text.
 * @param y Lower left corner of the text.
 * @param textcolor This is the color of the main text.
 * @param strokecolor This is the color of the text border.
 * @param fontfile The path to the TrueType font you wish to use.
 * @param text The text string in UTF-8 encoding.
 * @param px Number of pixels the text border will be.
 * @return Returns an array with 8 elements representing four points making the bounding 
 *         box of the text. The order of the points is lower left, lower right, upper right, 
 *         upper left. The points are relative to the text regardless of the angle, so 
 *         "upper left" means in the top left-hand corner when you see the text horizontally.
 * @see http://us.php.net/manual/en/function.imagettftext.php
 * @see http://forum.codecall.net
 * @see http://www.extreme-hq.com
 */
function imagettfstroketext(&$image$size$angle$x$y, &$textcolor, &$strokecolor$fontfile$text$px) {

    for(
$c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
        for(
$c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
            
$bg imagettftext($image$size$angle$c1$c2$strokecolor$fontfile$text);

   return 
imagettftext($image$size$angle$x$y$textcolor$fontfile$text);

Usage:
PHP Code:
$img imagecreatefrompng("/home/john/Desktop/test.png");
$font_color imagecolorallocate($img000);
$stroke_color imagecolorallocate($img25500);
$font "/home/john/Desktop/ABSTRACT.TTF";
$txt "This is a test..";
$px 2;
imagettfstroketext($img1001050$font_color$stroke_color$font$txt$px); 
Enjoy!

Last edited by John; 05-04-2008 at 01:37 PM.
Reply With Quote