Jump to content

Pilot ID Bagde


Vangelis

Recommended Posts

  • Members

Hello For the needs of my VA i created a Pilot badge with a modiefied version of signature function

This is the code this is for users that do know a litle bit of php and because it is a litle complicated i will NOT provide any support on that

the picture will be saved in the same folder as your signatures in the format id-PILOTID

Below is a screenshot where i use it as a possible use for you and the code.

The Name the rank and the date are coming dynamic from the database

the picture above the name comes dynamic from the avatar that the user has selected if none is selected then the default will show

the picture of the rank comes dynamic from the rank that you have as a pilot YOU MUST USE RELATIVE PATH in your admin section or else no pic will come on

like with the signature you must have a template so that everything comes to place you have to put it in /lib/signatures/backround/ with the name id.png

When you have done everything you need to call the function where ever you think for example whenever you send a pirep .

Good luck modiefing it

id-GSA0108.png

post-271-0-25787400-1373462582_thumb.png

public function generateid($pilotid)
{
$pilot = PilotData::getPilotData($pilotid);
$pilotcode = PilotData::getPilotCode($pilot->code, $pilot->pilotid);

if(Config::Get('TRANSFER_HOURS_IN_RANKS') === true)
{
$totalhours = $pilot->totalhours + $pilot->transferhours;
}
else
{
$totalhours = $pilot->totalhours;
}


$mysqldate = date( 'Y-m-d ', $pilot->joindate );
# Configure what we want to show on each line
$output = array();
$output[] = $pilot->firstname.' '.$pilot->lastname;
$output[] = $pilotcode;
$output[] = $pilot->rank;
$output[] = $pilot->retired;
$output[] = $mysqldate;

if(Config::Get('SIGNATURE_SHOW_EARNINGS') == true)
{
$output[] = 'Total Earnings: ' . $pilot->totalpay;
}

# Load up our image
# Get the background image the pilot selected
if(empty($pilot->bgimage))
$bgimage = SITE_ROOT.'/lib/signatures/background/id.png';
else
$bgimage = SITE_ROOT.'/lib/signatures/background/id.png';

if(!file_exists($bgimage))
{
# Doesn't exist so use the default
$bgimage = SITE_ROOT.'/lib/signatures/background/id.png';

if(!file_exists($bgimage))
{
return false;
}
}

$img = @imagecreatefrompng($bgimage);
if(!$img)
{
$img = imagecreatetruecolor(300, 50);
}

$height = imagesy($img);
$width = imagesx($img);

$txtcolor = str_replace('#', '', Config::Get('SIGNATURE_TEXT_COLOR'));
$color = sscanf($txtcolor, '%2x%2x%2x');
$textcolor = imagecolorallocate($img, $color[0], $color[1], $color[2]);
$font = 3; // Set the font-size

$xoffset = "150"; # How many pixels, from left, to start
$yoffset = "200"; # How many pixels, from top, to start

$font = Config::Get('SIGNATURE_FONT_PATH');
$font_size = Config::Get('SIGNATURE_FONT_SIZE');

if(function_exists('imageantialias'))
{
imageantialias($img, true);
}


/* Font stuff */

if(!function_exists('imagettftext'))
{
Config::Set('SIGNATURE_USE_CUSTOM_FONT', false);
}

# The line height of each item to fit nicely, dynamic

if(Config::Get('SIGNATURE_USE_CUSTOM_FONT') == false)
{
$stepsize = imagefontheight($font);
$fontwidth = imagefontwidth($font);
}
else
{
// get the font width and step size
$bb = imagettfbbox ( $font_size, 0, $font, 'A');

$stepsize = $bb[3] - $bb[5] + Config::Get('SIGNATURE_FONT_PADDING');
$fontwidth = $bb[2] - $bb[0];
}


$currline = $yoffset;
$total = count($output);

if(Config::Get('SIGNATURE_USE_CUSTOM_FONT') == false)
{
imagestring($img, $font, $xoffset, $currline, $output[$i], $textcolor);
}
else
{
// Use TTF
$tmp = imagettftext($img, $font_size, 0, 30, 220, $textcolor, $font, $output[0]);
$tmp = imagettftext($img, $font_size, 0, 265, 335, $textcolor, $font, $output[2]);
$tmp = imagettftext($img, $font_size, 0, 215, 390, $textcolor, $font, $output[4]);
if ($output[3]==1)
{
$tmp = imagettftext($img, $font_size, 0, 240, 230, $textcolor, $font, 'Pilot Retired');
$tmp = imagettftext($img, 40, 50, 130, 300, $textcolor, $font, 'INVALID ID');
}
else
{
$tmp = imagettftext($img, $font_size, 0, 240, 230, $textcolor, $font,'Active Pilot');

}

// Flag is placed at the end of of the first line, so have that bounding box there
if($i==0)
{
$flag_bb = $tmp;
}
}

$currline+=$stepsize;


# Add the Avatar Picture, line it up with the first line, which is the
# pilot code/name

if(file_exists(SITE_ROOT.'/lib/avatars/'.$pilotcode.'.png'))
{

$avatarimg = imagecreatefrompng(SITE_ROOT.'/lib/avatars/'.$pilotcode.'.png');

if(Config::Get('SIGNATURE_USE_CUSTOM_FONT') == false)
{
$ret = imagecopy($img, $avatarimg, strlen($output[0])*$fontwidth,
($yoffset+($stepsize/2)-5.5), 0, 0, 50, 50);
}
else
{
# figure out where it would go
$ret = imagecopy($img, $avatarimg, 70, 100, 0, 0, 50, 60);

}

}
else
$avatarimg = imagecreatefrompng(SITE_ROOT.'/lib/images/noavatar.png');

if(Config::Get('SIGNATURE_USE_CUSTOM_FONT') == false)
{
$ret = imagecopy($img, $avatarimg, strlen($output[0])*$fontwidth,
($yoffset+($stepsize/2)-5.5), 0, 0, 50, 50);
}
else
{
# figure out where it would go
$ret = imagecopy($img, $avatarimg, 70, 100, 0, 0, 50, 50);

}




# Add the Rank image

$ext = substr($pilot->rankimage, strlen($pilot->rankimage)-3, 3);

# Get the rank image type, just jpg, gif or png
if($ext == 'png')
$rankimg = @imagecreatefrompng($pilot->rankimage);
elseif($ext == 'gif')
$rankimg = @imagecreatefromgif($pilot->rankimage);
else
$rankimg = @imagecreatefromjpg($pilot->rankimage);

if(!$rankimg) { echo '';}
else
{

$ret = imagecopy($img, $rankimg, 250, 260, 0, 0, 100, 60);
// imagecopy($img, $rankimg, $width-$r_width-$xoffset, $yoffset, 0, 0, $r_width, $r_height);
}


if(Config::Get('SIGNATURE_SHOW_COPYRIGHT') == true)
{
#
# DO NOT remove this, as per the phpVMS license
$font = 1;
$text = 'powered by phpvms, '. SITE_NAME.' ';
imagestring($img, $font, $width-(strlen($text)*imagefontwidth($font)),
$height-imagefontheight($font), $text, $textcolor);
}

imagepng($img, SITE_ROOT.SIGNATURE_PATH.'/id-'.$pilotcode.'.png', 1);
imagedestroy($img);
echo $pilot->retired;
}

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...