Revision [3989]

This is an old revision of BannerMaker made by GmBowen on 2005-01-05 00:51:13.

 

Banner Generator


The following action can be used generate colored banners on wiki pages by using GD (required on the server) and fonts provided by the administrator. (TTF fonts must me placed in a directory "fonts" in a directory called scripts in the wikka root). On my server with 6 installed fonts it provides the following output.....
http://gmbowen.educ.unb.ca/wikitest/bannermaker.jpg
Place this code in the actions directory as banner.php
<?php
// action to call bannermaker.php to generate banners ...bannermaker REQUIRES GD2 on the server
// code written by GMBowen (with some help from JavaWoman) for wikka wiki. Version 1b
// licensed under GPL
// Use is {{banner text="Sample Text" [color="blue"] [size="20"] [font = "1"]}}
// Parameters in square brackets are optional....defaults to blue, 8 point, verdana
// Available colors are blue, red, purple, yellow, green, grey, white
// TTF Fonts must be obtained & uploaded by administrator & placed in a directory "fonts" in a
// directory called scripts placed in the wikka root

// set up variables
$site_base = $this->GetConfigValue("base_url");
if ( substr_count($site_base, 'wakka.php?wakka=') > 0 ) $site_base = substr($site_base,0,-16);
$generator = $site_base."scripts/bannergenerator.php?";
$buttoncolor = $color;

// Set below fonts to those present in fonts directory (which the admin makes in the scripts directory in the wikka root)
// Set the first font to that which you wish to be your default if a font isn't specified
// The administrator can add as many different fonts as they wish
if(!$font) {$font = "1";}
if ($font == "1"){$font = "verdana.ttf";}
if ($font == "2"){$font = "toby.ttf";}
if ($font == "3"){$font = "times.ttf";}
if ($font == "4"){$font = "vera.ttf";}
if ($font == "5"){$font = "oldeng.ttf";}
if ($font == "6"){$font = "courierbld.ttf";}

// create img tag
echo '<img src="'.$generator.'buttoncolor='.$buttoncolor.'&amp;font_size='.$size.'&amp;font_file='.$font.'&amp;text='.$text.'" alt="'.$text.'" border="0" />';
?>


This file is also required in a directory called scripts in the wikka root as bannergenerator.php
<?
// Adapted from a script provided at http://www.geek247.net/ and originally written by
// William Magliano. Modified by GMBowen 2005 for inclusion in Wikka Wiki &
// functionality increased. Released under GPL.
// Script REQUIRES GD2 on the server

$font_file = "./fonts/$font_file";
$defaultFontSize = 12;

if(!$font_size)// If no font size has been passed default to 12pt.
{
    $font_size = $defaultFontSize;
}

$angle = 0;

$defaultbgColor = "blue";
$defaulttxtColor = "black";

if(!$buttoncolor)//If no button color is passed make it Blue.
{
    $buttoncolor = $defaultbgColor;
}

if(!$textcolor)//If no text color is passed make it Black.
{
    $textcolor = $defaulttxtColor; 
}

//$textcolor= "red";

$y_start = $font_size*1.5;
$x_start = 5;
$double_text = $text;
$height = $font_size*2;

$bounding_box = imagettfbbox($font_size, 0, $font_file, $text);
$max_width = $bounding_box[2] - $bounding_box[0]+12;

// Create image and allocate colors
$im = imagecreate(($max_width+2), /*15*/$height);
$matte = imagecolorallocate($im, 153, 153, 153);

// allocate code for colors for background
if($buttoncolor == "blue")
{  
    $outline = imagecolorallocate($im, 0, 105, 179);// dark
    $shadow = imagecolorallocate($im, 113, 196, 240);// light
    $background = imagecolorallocate($im, 153, 176, 200);//lighter - brighter
    $hilite = imagecolorallocate($im, 240, 243, 247);//lightest
   
}
if($buttoncolor == "red")
{  
    $outline = imagecolorallocate($im, 255,0,0);// dark
    $shadow = imagecolorallocate($im,255,51,51);// light
    $background = imagecolorallocate($im,  255,102,102);//lighter - brighter
    $hilite = imagecolorallocate($im, 255,204,204);//lightest
}
if($buttoncolor == "purple")
{  
    $outline = imagecolorallocate($im, 255,0,255);// dark
    $shadow = imagecolorallocate($im,255,51,255);// light
    $background = imagecolorallocate($im,  255,102,255);//lighter - brighter
    $hilite = imagecolorallocate($im, 255,204,255);//lightest
}
if($buttoncolor == "yellow")
{  
    $outline = imagecolorallocate($im, 153,153,51);// dark
    $shadow = imagecolorallocate($im,204,204,102);// light
    $background = imagecolorallocate($im,255,255,102);//lighter - brighter
    $hilite = imagecolorallocate($im, 255,255,204);//lightest
}
if($buttoncolor == "green")
{  
    $outline = imagecolorallocate($im, 0,153,0);// dark
    $shadow = imagecolorallocate($im,0,204,0);// light
    $background = imagecolorallocate($im,102,204,102);//lighter - brighter
    $hilite = imagecolorallocate($im, 204,255,204);//lightest
}
if($buttoncolor == "grey")
{  
    $outline = imagecolorallocate($im, 102,102,102);// dark
    $shadow = imagecolorallocate($im,153,153,153);// light
    $background = imagecolorallocate($im,204,204,204);//lighter - brighter
    $hilite = imagecolorallocate($im, 255,255,255);//lightest
}

if($buttoncolor == "white")
{  
    $outline = imagecolorallocate($im, 255,255,255);// white
    $shadow = imagecolorallocate($im,255,255,255);// white
    $background = imagecolorallocate($im,255,255,255);// white
    $hilite = imagecolorallocate($im, 255,255,255);// white
}

if($buttoncolor == "black")
{  
    $outline = imagecolorallocate($im, 0,0,0);// black
    $shadow = imagecolorallocate($im,0,0,0);// black
    $background = imagecolorallocate($im,0,0,0);// black
    $hilite = imagecolorallocate($im, 0,0,0);// black
}

// allocate code for colors for the text
if($textcolor == "blue")
{  
    $text_color = imagecolorallocate($im, 153, 176, 200);
}
if($textcolor == "red")
{  
    $text_color = imagecolorallocate($im, 255, 102, 102);
}
if($textcolor == "purple")
{  
    $text_color = imagecolorallocate($im, 255, 102, 255);
}
if($textcolor == "yellow")
{  
    $text_color = imagecolorallocate($im, 255, 255, 102);
}
if($textcolor == "green")
{  
    $text_color = imagecolorallocate($im, 102, 204, 102);
}
if($textcolor == "grey")
{  
    $text_color = imagecolorallocate($im, 204, 204, 204);
}

if($textcolor == "white")
{  
    $text_color = imagecolorallocate($im, 255, 255, 255);
}

if($textcolor == "black")
{  
    $text_color = imagecolorallocate($im, 0, 0, 0);
}

imagefilledrectangle($im, 1, 1, $max_width, ($height-2), $background);
imageline($im, 0, 1, 0, ($height-2), $outline);
imageline($im, 1, 0, $max_width, 0, $outline);
imageline($im, ($max_width+1), 1, ($max_width+1), ($height-2), $outline);
imageline($im, 1, ($height-1), $max_width, ($height-1), $outline);
imageline($im, 2, 1, ($max_width-1), 1, $hilite);
imageline($im, $max_width, 2, $max_width, ($height-3), $hilite);
imageline($im, 1, 1, 1, ($height-3), $shadow);
imageline($im, 2, ($height-2), $max_width, ($height-2), $shadow);

// Position the text
$line_width = imagettfbbox($font_size, 0, $font_file, $text);
$horz_pos = (($max_width - $line_width[2] - $line_width[0]) / 2);

// Write the text to the image
imagettftext($im, $font_size, $angle, $x_start, $y_start, $text_color, $font_file, $double_text);

// Display and destroy the image
header("Content-type:image/png");
imagepng($im);
imagedestroy($im);
?>
There are 45 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki