Jump to content

Requesting help in pilot digital cards template


BADAWIAVGEEK

Recommended Posts

Hello Guys,

I'm a bit new to coding stuff but I got whats enough for me, currently i'm looking for help about generate function that isn't working with me.

I'm making a digital pilot card in the same page of the pilot badge, I did edit PilotData.Class.php , profile_badge.tpl in the skin , local.config.php & uploaded files in lib as /lib/dcards/background/background.png also made a blank index.php under /lib/dcards but it's not generating anything even after filing a PIREP while the badge is working properly.

Base codes are copy rights to their owner (Pilot Badge template Author)*

PilotData.Class.php


	public static function generateDcard($pilotid)
	{
		$pilot = self::getPilotData($pilotid);
		$pilotcode = self::getPilotCode($pilot->code, $pilot->pilotid);

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

		# Configure what we want to show on each line
		$output = array();
		$output[] = $pilot->firstname.' '.$pilot->lastname;
		$output[] = $pilotcode;
		$output[] = $pilot->rank;
		$output[] = $pilot->lastpirep;
		$output[] = $pilot->joindate;

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

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

		if(!file_exists($bgimage))
		{
			# Doesn't exist so use the default
			$bgimage = SITE_ROOT.'/lib/dcards/background/background.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('DCARD_TEXT_COLOR'));
		$color = sscanf($txtcolor, '%2x%2x%2x');
		$textcolor = imagecolorallocate($img, $color[0], $color[1], $color[2]);
		$font = 6; // Set the font-size

		$xoffset = Config::Get('DCARD_X_OFFSET'); # How many pixels, from left, to start
		$yoffset = Config::Get('DCARD_Y_OFFSET'); # How many pixels, from top, to start

		$font = Config::Get('DCARD_FONT_PATH');
		$font_size = Config::Get('DCARD_FONT_SIZE');

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


		/* Font stuff */

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

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

		if(Config::Get('DCARD_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('DCARD_FONT_PADDING');
			$fontwidth = $bb[2] - $bb[0];
		}


		$currline = $yoffset;
		$total = count($output);
		for($i=0;$i<$total;$i++)
		{
			if(Config::Get('DCARD_USE_CUSTOM_FONT') == false)
			{
				imagestring($img, $font, $xoffset, $currline, $output[$i], $textcolor);
			}
			else
			{
				// Use TTF
				$tmp = imagettftext($img, $font_size, 0, $xoffset, $currline, $textcolor, $font, $output[$i]);

				// 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 country flag, line it up with the first line, which is the
		#	pilot code/name
		$country = strtolower($pilot->location);
		if(file_exists(SITE_ROOT.'/lib/images/countries/'.$country.'.png'))
		{
			$flagimg = imagecreatefrompng(SITE_ROOT.'/lib/images/countries/'.$country.'.png');

			if(Config::Get('DCARD_USE_CUSTOM_FONT') == false)
			{
				$ret = imagecopy($img, $flagimg, strlen($output[0])*$fontwidth,
							($yoffset+($stepsize/2)-5.5), 0, 0, 16, 11);
			}
			else
			{
				# figure out where it would go
				$ret = imagecopy($img, $flagimg, $flag_bb[4]+5, $flag_bb[5]+2, 0, 0, 16, 11);
			}
		}

		# Add the Rank image
		if(Config::Get('DCARD_SHOW_RANK_IMAGE') == false && $pilot->rankimage!=''
				&& file_exists($pilot->rankimage))
		{
			$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
			{
				$r_width = imagesx($rankimg);
				$r_height = imagesy($rankimg);

				imagecopy($img, $rankimg, $width-$r_width-$xoffset, $yoffset, 0, 0, $r_width, $r_height);
			}
		}

		if(Config::Get('DCARD_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.DCARD_PATH.'/'.$pilotcode.'.png', 1);
		imagedestroy($img);
	}

 

profile_badge.tpl

 <h1 align="center">Pilot Digital Card</h1>

<p align="center">
	<img src="<?php echo $dcard_url ?>" />
</p>
<p>
	<strong>Direct Link:</strong>
	<input onclick="this.select()" type="text" value="<?php echo $dcard_url ?>" style="width: 100%" />
	<br /><br />
	<strong>Image Link:</strong>
	<input onclick="this.select()" type="text" value='<img src="<?php echo $dcard_url ?>" />' style="width: 100%" />
	<strong>BBCode:</strong>
	<input onclick="this.select()" type="text" value='[img]<?php echo $dcard_url ?>[/img]' style="width: 100%" />
</p>

 

local.config.php


# Options for the dcard that's generated
Config::Set('DCARD_TEXT_COLOR', '#25275d');
Config::Set('DCARD_USE_CUSTOM_FONT', true);
Config::Set('DCARD_FONT_PATH', SITE_ROOT.'/lib/fonts/candara.ttf');
Config::Set('DCARD_FONT_SIZE', '8.84');
Config::Set('DCARD_X_OFFSET', '89');
Config::Set('DCARD_Y_OFFSET', '172');
Config::Set('DCARD_FONT_PADDING', 4);
Config::Set('DCARD_SHOW_EARNINGS', false);
Config::Set('DCARD_SHOW_RANK_IMAGE', false);
Config::Set('DCARD_SHOW_COPYRIGHT', true);

Thanks

FzalwOC.jpgbackground.png

Edited by BADAWIAVGEEK
explaination
Link to comment
Share on other sites

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...