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 6220603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:59:08+00:00 2026-05-24T07:59:08+00:00

Good day folks. Im wondering is there any way to dynamically add image from

  • 0

Good day folks.

Im wondering is there any way to dynamically add image from user computer to canvas.

For example I have:

<canvas id="canvas"></canvas>
<input type="file" id="image-chooser">

If user pick image with input it’s added to canvas.

Show me any path to follow, please.

Thank you!

  • 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-05-24T07:59:08+00:00Added an answer on May 24, 2026 at 7:59 am

    To do this you should be familiar with the HTML5 Canvas API and the File API. And of course, this feature is available in the browsers only support both HTML5 APIs.

    The process to do this is:

    1. Dispatch a change event to file input element.
    2. Get the uploaded file from the event handler and get a data URL by using the FileReader
      object.
    3. Make an img element with the data URL and draw it on the canvas.

    I made a simple example on jsfiddle. The code looks like this:

    <canvas id="canvas"></canvas>
    <input type="file" id="file-input">
    <script>
    $(function() {
        $('#file-input').change(function(e) {
            var file = e.target.files[0],
                imageType = /image.*/;
    
            if (!file.type.match(imageType))
                return;
    
            var reader = new FileReader();
            reader.onload = fileOnload;
            reader.readAsDataURL(file);
        });
    
        function fileOnload(e) {
            var $img = $('<img>', { src: e.target.result });
            $img.load(function() {
                var canvas = $('#canvas')[0];
                var context = canvas.getContext('2d');
    
                canvas.width = this.naturalWidth;
                canvas.height = this.naturalHeight;
                context.drawImage(this, 0, 0);
            });
        }
    });
    </script>
    

    There are plenty of good tutorials about the File API like this or this.

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

Sidebar

Related Questions

Good day! Is there any way to include a timer (timestamp?or whatever term it
Good day. Say, please, is there any chance to intercept and record NTFS activity?
Good day, I try to start new Activity from another. But it always crashed.
Good day! There is a problem: Selected piece of text. In the allocation is
Good day! I have an event handler that, when you add a document to
Good day, I'm having a little trouble with calculating number of days from now
Good day. I have a problem with launching program in emulator. There is a
Good day! I use file_get_contents for give answer from remote address and explode for
Good day, I was playing with the example found here on SO: PHP Socket
Good day everyone. I'm trying to figure out a way to use multiple flags

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.