Problem normal image @ testing server but online....

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
fortuyn
Forum Newbie
Posts: 2
Joined: Wed Jan 04, 2006 9:37 am

Problem normal image @ testing server but online....

Post by fortuyn »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi guys, 

I use this code to create images from database stats. When i use it on the testing server it works perfectly, but only it doesn't draw the filled rectangle. can anyone help me out on this one.. i've gone mad, looking at this code for hours.

Greets

Daniel

Code: Select all

function create_image($ar_hits,$amount,$name)	{
	
	$xax = 550;
	$yax = 301;
	
	// Create image

	$im = imagecreate($xax,$yax);
	
	// color allocation
	
	$white = imagecolorallocate($im,255,255,255);
	$gray = imagecolorallocate($im,200,200,200);
	$black = imagecolorallocate($im,0,0,0);
	$yellow = imagecolorallocate($im,250,210,119);
	
	// make image white
	
	imagefill($im,0,0,$white);
	
	// Zoek grootste kolom
	
	foreach($ar_hits as $b)		{
		if($b > $highest)	{
			$highest = $b;
			}
		}	
		
	if($highest == "")	{
		$highest = 1;
		}
		
	// Stel kolom multiplier in
	
	$deler = 300 / $highest;
	$multi = 0.98 * round($deler,3);
	
	// isotopen
	
	for($i=0;$i<=250;$i=$i+50)	{
		$high = 300 - $i;
		$txt_place = $high - 10;
		imageline($im,0,$high,$xax,$high,$gray);
		$value = floor($i / $multi); 
		imagestring($im,1,3,$txt_place,$value,$black);
	}

	// ---------------------------------------------------KOLOM--------------------------------

	// Column 1 coordinates
	
	$usable_space = $xax - 21;
	$width = floor($usable_space/ $amount);
	$start_y = 300;
	$start_x = 20;
	$start_x2 = $start_x + $width;

	// text coordinates

	$start_ys = 285;
	$start_xs = (($start_x + $start_x2)-6) / 2;

	for($i=1;$i<=$amount;$i++)	{
	
		// Setting empty columns at zero setting minus ten will make sure nothing is being drawn.
	
		if($ar_hits[$i]=="")	{

			imagestring($im,2,$start_xs,$start_ys,$i,$black);
			$start_xs = $start_xs + $width;
			$start_x = $start_x + $width;
			$start_x2 = $start_x2 + $width;	
		
			} 
		else 	{
			
			// Get column Higth.
	 
			$hight = 300 - $ar_hits[$i] * $multi;
		
			// draw columns & date
		 
			imagefilledrectangle($im,$start_x,$start_y,$start_x2,$hight,$yellow);
			imagerectangle($im,$start_x,$start_y,$start_x2,$hight,$black);
			imagestring($im,2,$start_xs,$start_ys,$i,$black);
		
			// Update coordinates for next column
		
			$start_xs = $start_xs + $width;
			$start_x = $start_x + $width;
			$start_x2 = $start_x2 + $width;	 
		}
	}
	 
	// Axes
	
	imageline($im,0,300,$xax,300,$black);
	imageline($im,0,300,0,0,$black);
	
	// Save image
	
	$docname = "./images/";
	$docname .= $name;
	$docname .= ".jpg";
	
	imagejpeg($im,$docname);
}

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

This is one of those annoying issues with PHP/GD that's only obvious if you know about it. imagerectangle() will work if you specify bottom-left, top-right .. but imagefilledrectangle() won't. You need to change it to be top-left, bottom-right.

Code: Select all

imagefilledrectangle($im,$start_x,$hight,$start_x2,$start_y,$yellow);
To highlight the difference, change your imagefilledrectangle() function to imageline().
fortuyn
Forum Newbie
Posts: 2
Joined: Wed Jan 04, 2006 9:37 am

Post by fortuyn »

Well thanks for the support anywayz, but I still find it very strange that it does work on my testing server.. but doesn't online.. :S:S

gr Daniel
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

talking outta my ass here, but could it be that you're using imagejpeg() with imagecreate() and not imagecreatetruecolor() ?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

The option to have the variable order as bottom-left,top-right is something that changed in a relatively recent version of GD. I imagine there must be a couple of minor versions difference between your test server and production server. Or something. I definitely get the same problem, and tweaking the order definitely fixes it.
Post Reply