Revision [3877]

This is an old revision of BannerMaker made by GmBowen on 2005-01-02 16:20:15.

 

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 the actions directory) See an example of it here.

place in actions directory as banner.php
<?php
/**
* Outputs a Banner...to enhance page look & layout.
*
* With this action a banner can be generated with set-able size, background color, font size & font.
*
* Requires GD2 on the server

* @author GmBowen (http://wikka.jsnx.com/GmBowen) (with help from JavaWoman), 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 the actions directory
*/


// set up variables
$site_base = $this->GetConfigValue("base_url");

// Below line might need to be modified to whatever is appropriate for your installation .... 'wikka.php?wakka='
if ( substr_count($site_base, 'wakka.php?wakka=') > 0 ) $site_base = substr($site_base,0,-16);
$generator = $site_base."actions/bannergenerator.php?";
$buttoncolor = $color;

// Set below fonts to those present in fonts directory (which the admin makes in the actions directory)
// 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 actions directory 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. 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 8pt.
{
    $font_size = $defaultFontSize;
}

$angle = 0;

$defaultColor = "blue";

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

$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);

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);// dark
    $shadow = imagecolorallocate($im,255,255,255);// light
    $background = imagecolorallocate($im,255,255,255);//lighter - brighter
    $hilite = imagecolorallocate($im, 255,255,255);//lightest
}

$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