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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:59:15+00:00 2026-06-14T07:59:15+00:00

I am not exactly sure how to describe the problem, so let me explain

  • 0

I am not exactly sure how to describe the problem, so let me explain it with an example.

  • Suppose I have a canvas setup with the width and height of 600×400.

  • Now, I can chose an image (which can be of any dimension but usually bigger than 600×400) and draw it on the canvas.

  • Now I need to crop the original image (suppose in this case it is 1000×500 px) to
    400×200 px.

How do I go about this to make sure I am cropping the original sized image while displaying the scaled down image on the canvas?

I am preferably looking at a completely client side solution.

  • 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-14T07:59:16+00:00Added an answer on June 14, 2026 at 7:59 am

    Live Demo

    Its actually very easy. All you need to do is draw the image to a canvas of the size you want, and call toDataUrl() on it afterwards to get the resulting image data. Drawing the image itself to a different canvas doesn’t affect the output at all as long as you are drawing the contents of the original image to the cropped area.

    var canvas = document.getElementsByTagName("canvas")[0],
        context = canvas.getContext("2d"),
        img = document.getElementsByTagName("img")[0];
    
    canvas.width = 600;
    canvas.height = 400;
    
    context.drawImage(img, 0,0,600,400);
    
    var croppedCanvas = document.getElementById("tempCanvas"),
        croppedCtx = croppedCanvas.getContext("2d");
    
    croppedCanvas.width = 400;
    croppedCanvas.height = 200;
    
    croppedCtx.drawImage(img, 0, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive my verbosity. I'm not exactly sure how to describe my situation. Given the
I'm not sure exactly how to describe what I want to do, so I'll
I'm not sure exactly how to describe what I want. I want to define
I'm not sure exactly how to explain this, so I'll just start with an
I'm not sure exactly how to describe this question, but here goes. I've got
I'm not exactly sure how to ask this so I'll give an example I
Not exactly sure on the terminology here but here I go basically I have
So, I'm not exactly sure what the problem is, but, when I try to
I'm not sure exactly how this is called but I'll try to describe as
I am not exactly sure how to describe this issue, but heres goes nothing....

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.