function forumbadge_run()
{
    global $session;
    $acctid = httpget("acctid");
    page_header("Badge!");
    //PHP's GD class functions can create a variety of output image
    //types, this example creates a jpeg
    header("Content-Type: image/jpeg");
    //open up the image you want to put text over
    $im = ImageCreateFromPng("modules/buttonbase.png");
    //The numbers are the RGB values of the color you want to use
    $black = ImageColorAllocate($im, 0, 0, 0);
    //The canvas's (0,0) position is the upper left corner
    //So this is how far down and to the right the text should start
    $start_x = 10;
    $start_y = 20;
    $sql = "SELECT race, login, level, dragonkills FROM " . db_prefix("accounts") . " WHERE acctid = {$acctid}";
    $result = db_fetch_assoc(db_query($sql));
    $name = $result['login'];
    $race = $result['race'];
    $level = "Level " . $result['level'];
    $dragonkills = "Drive Kills: " . $result['dragonkills'];
    debug($result);
    //This writes your text on the image in 12 point using verdana.ttf
    //For the type of effects you quoted, you'll want to use a truetype font
    //And not one of GD's built in fonts. Just upload the ttf file from your
    //c: windows fonts directory to your web server to use it.
    Imagettftext($im, 10, 0, 65, 12, $black, 'modules/verdana.ttf', $name);
    Imagettftext($im, 10, 0, 65, 27, $black, 'modules/verdana.ttf', $race);
    Imagettftext($im, 10, 0, 65, 42, $black, 'modules/verdana.ttf', $level);
    Imagettftext($im, 10, 0, 65, 57, $black, 'modules/verdana.ttf', $dragonkills);
    //Creates the jpeg image and sends it to the browser
    //100 is the jpeg quality percentage
    Imagejpeg($im, '', 60);
    ImageDestroy($im);
    page_footer();
}
Example #2
0
$radix_max = strlen($radix) - 1;
$maxlen = 4;
mt_srand();
$fpath = "img_rand/" . mt_rand(0, 6) . ".jpg";
$font = $_SERVER["DOCUMENT_ROOT"] . "/img_rand/font_rand/" . mt_rand(0, 9) . ".ttf";
$im = ImageCreateFromJPEG($fpath);
// width=200 height=10
$color = ImageColorAllocate($im, 0, 0, 0);
$len = $maxlen;
$bwidth = 200 / $maxlen;
$rand_str = "";
while ($len) {
    $len--;
    $i = mt_rand(0, $radix_max);
    $j = mt_rand(20, 30);
    $x = 170 - $len * $bwidth;
    $y = 15 + $j;
    $angle = $i - 15;
    Imagettftext($im, $j, $i - 15, $x, $y, $color, $font, $radix[$i]);
    $rand_str .= $radix[$i];
}
session_set_cookie_params(3600);
session_start();
$_SESSION['num_auth'] = str_replace(" ", "", $rand_str);
header("Content-Type: image/png");
ImagePng($im);
ImageDestroy($im);
exit;
?>

Example #3
0
function wtrmark($sourcefile, $watermarkfile, $text)
{
    $logopath = "/home/www/cb3/img/cb-logo-300.png";
    $logofile_id = imagecreatefrompng($logopath);
    imageAlphaBlending($logofile_id, true);
    imageSaveAlpha($logofile_id, true);
    $fileType = strtolower(substr($sourcefile, strlen($sourcefile) - 3));
    switch ($fileType) {
        case 'gif':
            $sourcefile_id = imagecreatefromgif($sourcefile);
            break;
        case 'png':
            $sourcefile_id = imagecreatefrompng($sourcefile);
            break;
        default:
            $sourcefile_id = imagecreatefromjpeg($sourcefile);
    }
    imageAlphaBlending($sourcefile_id, true);
    imageSaveAlpha($sourcefile_id, true);
    //Get the sizes of both pix
    $sourcefile_width = imageSX($sourcefile_id);
    $sourcefile_height = imageSY($sourcefile_id);
    $logo_width = imageSX($logofile_id);
    $logo_height = imageSY($logofile_id);
    $dest_x_logo = $sourcefile_width - $logo_width - 4;
    $dest_y_logo = $sourcefile_height - $logo_height - 8;
    // if a gif, we have to upsample it to a truecolor image
    if ($fileType == 'gif') {
        // create an empty truecolor container
        $tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
        // copy the 8-bit gif into the truecolor image
        imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);
        // copy the source_id int
        $sourcefile_id = $tempimage;
    }
    // create an empty truecolor container
    $tempimage = imagecreatetruecolor($sourcefile_width + 20, $sourcefile_height);
    $bgColor = imagecolorallocate($tempimage, 255, 255, 255);
    imagefill($tempimage, 0, 0, $bgColor);
    // copy the 8-bit gif into the truecolor image
    imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);
    // copy the source_id int
    $sourcefile_id = $tempimage;
    //text
    $black = ImageColorAllocate($sourcefile_id, 200, 200, 200);
    $white = ImageColorAllocate($sourcefile_id, 255, 255, 255);
    //The canvas's (0,0) position is the upper left corner
    //So this is how far down and to the right the text should start
    $start_x = $sourcefile_width;
    $start_y = $sourcefile_height;
    // write text
    Imagettftext($sourcefile_id, 10, 90, $sourcefile_width + 11, $sourcefile_height, $black, '/home/www/cb3/ales/arial.ttf', $text);
    $opacity_logo = 30;
    ImageCopyMerge($sourcefile_id, $logofile_id, $dest_x_logo, $dest_y_logo, 0, 0, $logo_width, $logo_height, $opacity_logo);
    //Create a jpeg out of the modified picture
    switch ($fileType) {
        // remember we don't need gif any more, so we use only png or jpeg.
        // See the upsaple code immediately above to see how we handle gifs
        case 'png':
            imagepng($sourcefile_id, $sourcefile);
            break;
        default:
            imagejpeg($sourcefile_id, $sourcefile);
    }
    imagedestroy($sourcefile_id);
    imagedestroy($logofile_id);
}
Example #4
0
     } else {
         // if background is not a hex color but is in array and file for the background image exist //
         $backgroundFile = "colorpicker/background/{$backgroundColor}.png";
         if (file_exists($backgroundFile)) {
             $background = imagecreatefrompng($backgroundFile);
         } else {
             exit;
         }
     }
     if (array_key_exists($textColor, $allowedColors)) {
         $txtRGB = sscanf($textColor, '%2x%2x%2x');
         $txtColor = imagecolorallocate($background, $txtRGB[0], $txtRGB[1], $txtRGB[2]);
     }
 }
 $fcolor = imagecolorallocate($background, 255, 255, 255);
 Imagettftext($background, 280, 0, 60, 280, $txtColor, $font, 'A');
 // draw borders //
 imagesetthickness($background, 2);
 $grey = imagecolorallocate($background, 153, 153, 153);
 $x = 0;
 $y = 0;
 $w = imagesx($background) - 0;
 $z = imagesy($background) - 0;
 imageline($background, $x, $y, $x, $y + $z, $grey);
 imageline($background, $x, $y, $x + $w, $y, $grey);
 imageline($background, $x + $w, $y, $x + $w, $y + $z, $grey);
 imageline($background, $x, $y + $z, $x + $w, $y + $z, $grey);
 $file = "colorpicker/cache/{$backgroundColor}-{$textColor}.png";
 imagepng($background, $file);
 imagepng($background);
 imagedestroy($background);