Jump to content

[SOLVED] PHP GD Image Rotation with building PHP Graphs


thepip3r

Recommended Posts

5 |
4 |             .
3 |      .
2 |         .      .  .
1 |   .
   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
       a b c d e f g

 

in my graph, the x axis heading values are actual date strings and they are vertically oriented using imagestringup().  i've tried assigning the value of imagestringup to a variable and then use that for the imagerotate() but i get an error when i do that.  can anyone point me in the right direction pls?

 

for($i=0;$i< $total_points; $i++){ 
# ------ Extract key and value pair from the current pointer position
list($key,$value)=each($array); 
$x1 = $margins + $gap + $i * ($gap+$bar_width);
$x2 = $x1 + $bar_width; 
$y1 = $margins + $graph_height - intval($value * $ratio) ;
$y2 = $img_height-$margins;
imagestring($img,0,intval(($bar_width-(strlen(trim($value)) * 6.5)) / 2) + $x1,$y1-10,$value,$bar_color); # numeric values written to screen
$temp = imagestringup($img,0,$x1-2,$img_height-5, date("m/d/y D", $key),$bar_color);	# x-axis heading values	
imagerotate($img, 90, 0);
imagefilledellipse($img,$x1,$y1,5,5,$bar_color);
if ($i > 0) { imageline($img, $x0, $y0, $x1, $y1, $bar_color); }
$x0 = $x1;
$y0 = $y1;		
}
header("Content-type:image/png");
imagepng($img);

Link to comment
Share on other sites

Warning: imagerotate() expects parameter 1 to be resource, boolean given in public_html/trigeo/graph_line.php on line 157

 

when i change the above code to:

 

$temp = imagestringup($img,0,$x1-2,$img_height-5, date("m/d/y D", $key),$bar_color);	# x-axis heading values	
imagerotate($temp, 90, 0);

Link to comment
Share on other sites

right and i understood that... i'm trying to rotate the x-axis headers say 45 degrees so they're not vertical but slightly angled.  all of the examples i can find are just creating a rotated image on the fly but not one that is created within the context of an existing "graph" image. 

 

do i ahve to create that x axis value as a separate image or something and then merge it into the graph body in order to get the x-axis headers rotated correctly?

Link to comment
Share on other sites

Alex -- worked like a champ.  http://www.zigsdigs.com/trigeo/graph_line.php

 

now i just have to figure out how to calculate the x-offset so the end of the line is adjusted to the actual point instead of the start of the lean.

 

i always read the manual, i just got to imagerotate() and got stuck and never looked any further -- my bad.  ty for the help guys.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.