Jump to content

Signatures


CPC900

Recommended Posts

Ok, I have read the forum, but don't think the answer is there?!

I get this error now, and not sure why or what I might have done to get it:

Warning: imagepng() [function.imagepng]: Unable to open '/home/########/public_html/CPC//lib/signaturesCPC0001.png' for writing: Permission denied in /home/########/public_html/CPC/core/common/PilotData.class.php on line 1001

Now I noticed a double "//" above in the "/home/########/public_html/CPC//lib/signaturesCPC0001.png" part and was wondering if that is the problem? If it is, I have no idea why there are 2 slashes there?!?

Line 1001 in my PilotData.class.php is:


imagepng($img, SITE_ROOT . SIGNATURE_PATH . '/' . $pilotcode . '.png', 1);

Link to comment
Share on other sites

You could try to see if this is what is located in your PilotData.class.php to see if it is missing something.

/**
 * This generates the forum signature of a pilot which
 *  can be used wherever. It's dynamic, and adjusts it's
 *  size, etc based on the background image.
 * 
 * Each image is output into the /lib/signatures directory,
 *  and is named by the pilot code+number (ie, VMA0001.png)
 * 
 * This is called whenever a PIREP is accepted by an admin,
 *  as not to burden a server with image generation
 * 
 * Also requires GD to be installed on the server
 * 
 * @param int The pilot ID for which to generate a signature for
 * @return bool Success
 */	 
public function generateSignature($pilotid)
{
	$pilot = self::getPilotData($pilotid);
	$last_location = PIREPData::getLastReports($pilotid, 1, PIREP_ACCEPTED);
	$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[] = $pilotcode.' '. $pilot->firstname.' '.$pilot->lastname;
	$output[] = $pilot->rank.', '.$pilot->hub;
	$output[] = 'Total Flights: ' . $pilot->totalflights;
	$output[] = 'Total Hours: ' . $totalhours;
	$output[] = 'Current Location: ' . $last_location->arricao;

	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/background.png';
	else
		$bgimage = SITE_ROOT.'/lib/signatures/background/'.$pilot->bgimage;

	if(!file_exists($bgimage))
	{
		# Doesn't exist so use the default
		$bgimage = SITE_ROOT.'/lib/signatures/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('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 = Config::Get('SIGNATURE_X_OFFSET'); # How many pixels, from left, to start
	$yoffset = Config::Get('SIGNATURE_Y_OFFSET'); # 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);
	for($i=0;$i<$total;$i++)
	{		
		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, $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('SIGNATURE_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('SIGNATURE_SHOW_RANK_IMAGE') == true && $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('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.'/'.$pilotcode.'.png', 1);
	imagedestroy($img);
}
}

It may also be in the way the path is written. You can see if the signature is supposed to be written after the CPC/ or the CPC. If it is after the CPC/ then you might want to remove the / or just route it to the full URL.

Link to comment
Share on other sites

I will review the code when I get home later. As for the "/", I did remove that just to see, but no luck. I will copy and paste your code here to see. But I was wondering if I would have changed the PilotData.class.php code for some reason?! I sure don't remember why, if I did. Thanks, will keep u posted.

Link to comment
Share on other sites

  • 5 months later...

Dave, sorry to come back to this after so long, but I never did get it fixed :(

As for what you said above, where EXACTLY did you mean, when you said:

It is a directory issue, I ran into the same thing. For my fix I just has to use the complete absolute url in the ranks image setting.

http://www.yoursite.com/path to image

not

/path to image

Link to comment
Share on other sites

  • Administrators

It has been a while but I think this falls back to the pilot rank images and not using relative paths in the admin center.

In the pilot ranks admin panel instead of

/lib/images/ranks/newhire.png

Use

http://www.mysite.com/lib/images/ranks/newhire.png

Link to comment
Share on other sites

Ok, I finally fixed it, after reading over and over again what you all told me :lol: Sorry, but sometimes, I am a total MORON apparently. It is good now. The folder permissions were fine, but I made the .png files all 777 in the signatures folder and all is fine. The individual .png files were 644 or something. Not sure why that was.

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