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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:11:38+00:00 2026-06-10T18:11:38+00:00

See http://jsfiddle.net/jdb1991/6sxke/ I’ve got a canvas element that doesn’t know what it’s going to

  • 0

See http://jsfiddle.net/jdb1991/6sxke/

I’ve got a canvas element that doesn’t know what it’s going to be used for until an image has loaded, so I need to be able to change the dimensions of the element on the fly, after creating the image object.

Something is going wrong though, as it seems to be running the commands asynchronously; writing the image to the context before the resize occurs.

  • 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-10T18:11:40+00:00Added an answer on June 10, 2026 at 6:11 pm

    use:

    function objectifyImage(i) {
        var img_obj = new Image();
        img_obj.src = i;
        return img_obj;
    }
    
    var canvas = document.getElementById('display');
    var context = canvas.getContext('2d');
    i = objectifyImage('https://www.google.co.uk/images/srpr/logo3w.png');
    i.onload = function() {
        canvas.width = i.width;
        canvas.height = i.height;
    
        context.drawImage(i, 0, 0);
    };
    ​
    

    demo: http://jsfiddle.net/ycjCe/1/


    The element can be sized arbitrarily by CSS, but during rendering the
    image is scaled to fit its layout size. (If your renderings seem
    distorted, try specifying your width and height attributes explicitly
    in the attributes, and not with CSS.)

    source: https://developer.mozilla.org/en-US/docs/Canvas_tutorial/Basic_usage

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

Sidebar

Related Questions

Canvas with absolute position doesn't work as you can see here: http://jsfiddle.net/733zs/1/ (Tested in
I've got a toggle menu, please see http://jsfiddle.net/Wp2em/41/ for code and functions. On the
See here for my issue: http://jsfiddle.net/FvBqA/126/ My issue is that I want to be
Please see http://jsfiddle.net/jGCx9/ I have right: 28px which causes the span element to shift
the .click() event doesn't seem to work on select, please see: http://jsfiddle.net/fMTzD/ Even before
I have the following fiddle for people to see http://jsfiddle.net/defaye/DhaHP/4/ The result on full
I'm running this code in Firefox 11 on Windows 7. (See http://jsfiddle.net/QStkd/ ). $('<div><input
See here: http://jsfiddle.net/zYcJm/ The jQuery should be validating each field to check if they
I have a menu with tiled images w/text under them. See Fiddle: http://jsfiddle.net/techydude/GF8tS/ Is
See the fiddle: http://jsfiddle.net/stefek99/9m5NZ/1/ Get the source: http://pastie.org/3654715 Chrome 17 : just works. IE

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.