Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8542675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:07:28+00:00 2026-06-11T12:07:28+00:00

I have an image in html img tag. My requirement is that when a

  • 0

I have an image in html img tag. My requirement is that when a user click on the image it will mark a point and draw a line while dragging the mouse. Then, While user finishes the drag and clicks on the image it should display the line also show the dimension of the line in millimeter/centimeter. ie , User has to draw a line on the image and show the distance/length (in millimeter/centimeter)of line he drawn.

How can implement this feature in a web application? Can anyone please help me to implement this feature ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:07:29+00:00Added an answer on June 11, 2026 at 12:07 pm

    Use the html5 canvas element, set the image as a css background to the canvas element (makes drawing the lines easier because you don’t have to redraw the image) and draw the line on the canvas:

    1) On mousedown, record the mouse position and register a mousemove handler closed around those starting positions, and register a mouseup handler to remove the mousemove handler.

    2) In the mousemove handler, find the offset between the current mouse position and the mouse’s starting position, add this offset to the starting line position and then redraw the canvas using this new position.

    You can’t label the line with a physical distance because this will depend on the screen that displays your work. The best you can do is decide on a scale/print resolution for your image (in dpi, e.g. 300 pixels per inch) and calculate the length of the line based on that. The exact implementation depends on how you want to use the results.

    UPDATE: EXAMPLE

    DEMO JSFIDDLE

    HTML

    <canvas id="canvas" width="200" height="200">
        Your browser doesn't support canvas
    </canvas>
    

    CSS

    canvas{
        background-image: url("image.jpg");
        background-position: center;
        background-size: 100% 100%;
    }
    

    JS

    $(document).ready(function(){
    
        var imageDpi = 300;
    
        var can = document.getElementById('canvas');
        var ctx = can.getContext('2d');
        var startX, startY;
    
        $("canvas").mousedown(function(event){
            startX = event.pageX;
            startY= event.pageY;
    
            $(this).bind('mousemove', function(e){
                drawLine(startX, startY, e.pageX, e.pageY);
            });
        }).mouseup(function(){
            $(this).unbind('mousemove');
        });
    
        function drawLine(x, y, stopX, stopY){
            ctx.clearRect (0, 0, can.width, can.height);
            ctx.beginPath();
            ctx.moveTo(x, y);
            ctx.lineTo(stopX, stopY);
            ctx.closePath();
            ctx.stroke();
    
            // calculate length   
            var pixelLength = Math.sqrt(Math.pow((stopX - x),2) + Math.pow((stopY-y),2));
            var physicalLength = pixelLength / imageDpi;
            console.log("line length = " + physicalLength + 
                        " inches (image at " + imageDpi + " dpi)");
        }
    });
    

    UPDATE 2: LINE LENGTH

    I updated my example. It defines the image’s physical resolution and calculates the line’s length based on that assumption.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does asp:Image tag perform faster than normal HTML img tag? I have 20 images
We have alternate text, alt attribute, for an img tag in HTML, which will
I have the following HTML <div id=testID class=test1> <img id=testID2 class=test2 alt= src=some-image.gif />
I have a few html image tags that fill an array. On the page
I have a string that contains HTML image elements that is stored in a
I have populated an array with a few html image tags that I have
I have an img tag in my webapp that uses the onload handler to
I have the following regular expression to replace an html img tag with [IMG];
I have an image icon in an HTML page that should show right to
On typical html page, I have images using img tag with height and width

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.