Page 1 of 1

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

Posted: Wed Jan 04, 2006 9:42 am
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]

Posted: Wed Jan 04, 2006 11:07 am
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().

Posted: Thu Jan 05, 2006 7:05 am
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

Posted: Thu Jan 05, 2006 7:55 am
by feyd
talking outta my ass here, but could it be that you're using imagejpeg() with imagecreate() and not imagecreatetruecolor() ?

Posted: Thu Jan 05, 2006 10:48 am
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.