getting image coordinates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rekhamanoj
    New Member
    • Mar 2008
    • 3

    #1

    getting image coordinates

    hello i am new to PHP i have a linegraph created using GD function in PHP. Now what i need is when i roll the mouse over the graph i want to draw a straight line and want to display the image coordinates of plots in my graph which intersects this straight line i got stuck up in my project because of this issue please help me thanks in advance

    rekhamanoj
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    I am pretty sure you will need to use AJAX or javascript for that. I haven't used the GD a lot, but I think once you have requested the page the image is set, so you can't draw lines. Definately for displaying live coordinates you should use AJAX or javascript. Wait for others to confirm this before you give up though. Do you have any AJAX or javascript experience?

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      PHP will only work server-side, so no client-side actions will ever trigger any PHP code. Unless that action is to send a fresh HTTP request, obviously.

      That can be achieved by using AJAX, but it won't be easy.
      You may be better of looking into Javascript solutions to this.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by rekhamanoj
        hello i am new to PHP i have a linegraph created using GD function in PHP. Now what i need is when i roll the mouse over the graph i want to draw a straight line and want to display the image coordinates of plots in my graph which intersects this straight line i got stuck up in my project because of this issue please help me thanks in advance

        rekhamanoj
        Its a rather tough job than what you would have expected.
        I can though suggest you an algorithm.
        • Keep the img inside a div with no other element along with it. just img in that div and give style="position :absolute;top:1 00px;left:100px ;padding:0px;bo rder-width:0px;" to the div.
        • onmousedown of this div, turn a flag var imageClicked = true;
        • onmousemove of the body, if imageClicked==t rue keep getting the mouse coordinates (you may get many functions for that on google) and keep creating div elements and append them to the body, with style="position :absolute;width :1px;height:1px ;background-color:black;" and with JavaScript, make its left and top equal to the x and y coordinates of cursor respectively. This will give a line drawing view. Also keep saving the coordinates in an array. You would need to send this array to PHP to change the actual image. To display the coordinates, display them in any span or div by innerHTML
        • onmouseup of the body, turn that imageClicked=fa lse; and call an Ajax function to post array of coordinates to PHP
        • Subtract 100 (same as you had given left and top to the div containing image) from the coordinates posted by Ajax and draw them on the image by GD.


        Not properly explained, but hope you can make out.

        Regards

        Comment

        Working...