php graphics and graph

Discussion in 'PHP' started by mdrobiul, Jun 10, 2009.

  1. #1
    Hi,

    Php generates line with 0,0 coordinate from top-left. Is there any easy way to draw line with 0,0 from bottom-left. You know that we generally draw graph 0,0 from bottom-left. i know that i can think of multiplying or dividing etc. for replacing this. But you guys how you work with this problem when you drawing grahp using line ??
     
    mdrobiul, Jun 10, 2009 IP
  2. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    If you know size of the image you can easily know the coords of all corners.
     
    stOK, Jun 10, 2009 IP
  3. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    list($width, $height, $type, $attr) = getimagesize("$image");
    
    PHP:
    $height is your bottom coordinate
     
    SHOwnsYou, Jun 10, 2009 IP
  4. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks for your reply. but i did not understand where you are trying to direct me.

    Can you please tell me what i can do in my graph code? May be then i can get it.

    <?php
    
    header("content-type:image/png");
    
    $x1=$_POST[x1];
    $x2=$_POST[x2];
    $x3=$_POST[x3];
    $x4=$_POST[x4];
    $x5=$_POST[x5];
    
    $y1=$_POST[y1];
    $y2=$_POST[y2];
    $y3=$_POST[y3];
    $y4=$_POST[y4];
    $y5=$_POST[y5];
    
    
    $im = @imagecreate(500,500) or die("Can not Initialize new GD image stream");
    
    $background_color = imagecolorallocate($im, 255,255,0);
    
    $white=imagecolorallocate($im, 255,255,255);
    $black=imagecolorallocate($im, 0,0,0);
    
    imageline($im,$x1,$y1,$x2,$y2,$black);
    imageline($im,$x2,$y2,$x3,$y3,$black);
    imageline($im,$x3,$y3,$x4,$y4,$black);
    imageline($im,$x4,$y4,$x5,$y5,$black);
    imageline($im,$x5,$y5,500,500,$black);
    
    imagepng($im);
    
    
    ?>
    PHP:
     
    mdrobiul, Jun 11, 2009 IP
  5. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    So what are you trying to do exactly? Draw from the bottom-left?
     
    SHOwnsYou, Jun 11, 2009 IP
  6. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yeah. all graphs are generally made with low to high value by drawing bottom to top. when i place values (because it's easy) at co-ordinates in line function it really generates graph but it's upside down (low at top and high at bottom). i want to set low at bottom and high at top is real life graph we use in our daily life.
     
    mdrobiul, Jun 11, 2009 IP
  7. alecs

    alecs Well-Known Member

    Messages:
    156
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #7
    I do not think you are able to change the reference coordinates (0,0) from the default corner.
    The way I see it, you have 2 options:
    1. You change all your $y coordinates to $height-$y
    2. You create your image and before saving it you flip is vertically. Use imagecopyresized for this.
     
    alecs, Jun 11, 2009 IP
  8. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks alecs. i understand the ways you're talking about. thanks.
     
    mdrobiul, Jun 12, 2009 IP