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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:02:31+00:00 2026-06-05T00:02:31+00:00

I have the following code : function createImage(source) { var pastedImage = new Image();

  • 0

I have the following code :

function createImage(source) {                
var pastedImage = new Image();                
pastedImage.onload = function() {                                        
document.write('<br><br><br>Image: <img src="'+pastedImage.src+'" height="700" width="700"/>');                                                                                                         
}
pastedImage.src = source;                
}

Here I am displaying the image through html image tag which I wrote in document.write and provide appropriate height and width to image.

My question is can it possible to displaying image into the canvas instead of html img tag? So that I can drag and crop that image as I want?

But how can I display it in canvas?

Further I want to implement save that image using PHP but for now let me know about previous issue.

  • 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-05T00:02:33+00:00Added an answer on June 5, 2026 at 12:02 am

    Try This

     var ctx = document.getElementById('canvas').getContext('2d');
    
        var img = new Image();   // Create new img element  
        img.onload = function(){  
          // execute drawImage statements here  This is essential as it waits till image is loaded before drawing it.
     ctx.drawImage(img , 0, 0);
    
        };  
        img.src = 'myImage.png'; // Set source path  
    

    Make sure the image is hosted in same domain as your site. Read this for Javascript Security Restrictions Same Origin Policy.

    E.g. If your site is http://example.com/
    then the Image should be hosted on http://example.com/../myImage.png

    if you try http://facebook.com/..image/ or something then it will throw security error.

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

Sidebar

Related Questions

I have the following code : function createImage(source) { var pastedImage = new Image();
I have the following code: function playSound(source) { document.getElementById(sound_span).innerHTML = <embed src=' + source
I have the following code: function show(){ var a=document.getElementById('somediv').style.display; a=block; } The above code
I have the following code: function reload() { var referenceID = $('#ReferenceID').val(); $('#detailData').load(Url.Action(DetailData, new
I have the following code: function showAddrBox() { var prompt = document.getElementById('addr_prompt'); prompt.style.display =
I have the following code: function removeUsers() { var removedUsers = document.getElementById('<%=removedUsers.ClientID%>'); var lbCurrent
I have the following example code: function drawCanvas() { var canvas = document.getElementById(logoText); var
I have the following JavaScript code - function addOnClickEventHandler() { var userNameElement = document.getElementById(currentUser);
I have the following code: function $(id) { return document.getElementById(id); } var material =
I currently have the following js code function clearMulti(option) { var i; var select

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.