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

  • Home
  • SEARCH
  • 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 6755667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:25:49+00:00 2026-05-26T13:25:49+00:00

Is it possible to set the width and height of a canvas element and

  • 0

Is it possible to set the width and height of a canvas element and have the existing content scale to fit these new dimensions?

Right now the user uploads an image and my page creates a canvas element containing this image and whose dimensions are the same size as the image. I want to limit the size that I’m working with, however, so here is an example of what I want to have happen:

  1. The user uploads an image that is 1600 x 1200 pixels (Not saved to server)
  2. The data goes right to an html5 canvas object
  3. The canvas height and width are set to 800 x 600 and the image content scales appropriately and then is displayed.

Right now if I set the canvas width and height it just crops the image at those dimension, not resizing as I would like. Thanks!

  • 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-26T13:25:50+00:00Added an answer on May 26, 2026 at 1:25 pm

    There are many ways to call drawImage

    One is:

    ctx.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh)

    Where dx,dy,dw,dh are the destination x, y, width, and height.

    If you make dw and dh always 800×600, the image will drawn will always automatically be scaled to 800×600.

    Here’s a tiny example that will always draw any size image to 800×600 http://jsfiddle.net/jAT8Y/

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

Sidebar

Related Questions

Is it possible to set the height/width of an element in percent using JavaScript
Is it possible to set width or height of HTML element (ex. <div> )
I have this function $(.container).width('1052').height($(.right).height()); And in the function the .container height is set
Is it possible to set the taskbar position/width/height using the windows API? I'm running
is it possible to set the width and height to auto in a fancybox
Is it possible to set height and width of tabs in Android? I tried
Is it possible to set branch permissions with Gitorious? I would like to have
Is it possible to set an elements width like this: <img id=backgroundImg src=images/background.png alt=
So I have an image that I need to call .width and .height but
Is it possible to set different texture filtering when working with sprites?

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.