Skip to content

Instantly share code, notes, and snippets.

@njames
Created April 17, 2013 00:33
Show Gist options
  • Save njames/5400832 to your computer and use it in GitHub Desktop.
Save njames/5400832 to your computer and use it in GitHub Desktop.
SAP Inside Track Logo Generator
<?php
/**
* @author Nigel James
* @email [email protected]
* @date 15 Apr 2013
*
* Create an image for SAP Inside Track events with Year and City
*/
function LoadPNG($pngName)
{
/* Attempt to open */
$im = @imagecreatefrompng($pngName);
/* See if it failed */
if(!$im)
{
/* Create a blank image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $pngName, $tc);
}
return $im;
} // LoadPNG
// set headers
header('Content-Type: image/png');
$logo = LoadPNG('sapitlogobase.png');
// get year and city validate and sanitise
$_year = $_GET['year'];
$_city = $_GET['city'];
// year
$yearText = (int) $_year;
if ($yearText == '0') {
$yearText = '';
}
// city - uppercase and sanitised
$cityText = htmlspecialchars(strtoupper($_city));
// get the text on the image
$yearColour = imagecolorallocate($logo, 0x6b, 0x6b, 0x6b); // web #6b6B6B
$cityColour = imagecolorallocate($logo, 0xF0, 0xAB, 0x00); // web #F0AB00
$font = 'ArialBold.ttf';
//imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
imagettftext($logo, 30, 0, 370, 35, $yearColour, $font, $yearText);
imagettftext($logo, 20, 0, 6, 60, $cityColour, $font, $cityText);
imagepng($logo);
imagedestroy($logo);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment