New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image filled even div set to object-fit: cover; #1064

LangRizkie opened this Issue Feb 27, 2017 · 2 comments


4 participants

LangRizkie commented Feb 27, 2017 | Pic 1 | Pic 2

Pic 1 is the div i want to capture, after it captured the image change its size *Pic 2.

Anyone could fix this ?

@niklasvh niklasvh added the Feature label Dec 12, 2017


This comment has been minimized.

LanderBeeuwsaert commented May 27, 2018

Hello, just to let you know that I needed this and hacked it to work in my project. I provide the code which works for me below. However this is a hack, I don't have the knowledge to integrate this into your project in a more proper way:

    key: 'drawImage',
      value: function drawImage(image, source, destination) {
        /**START CUSTOM CODE**/

          var newWidth = 30;
          var newHeight = 30;
          var newX = destination.left;
          var newY =;

          // console.log(image, source, destination);
          if (source.width/destination.width > source.height/destination.height) {
              newWidth = destination.width;
              newHeight = source.height * (destination.width / source.width);
              newY = + (destination.height - newHeight) / 2;
          } else {
              newWidth = source.width * (destination.height / source.height);
              newHeight = destination.height;
              newX = destination.left + (destination.width - newWidth) / 2;
        // console.log(newWidth, newHeight);

          this.ctx.drawImage(image, source.left,, source.width, source.height,
            newX, newY,
            newWidth, newHeight);
          // destination.width,
          // destination.height * (source.height / source.width)
          //   destination.width, destination.height);

        /**END CUSTOM CODE**/

This comment has been minimized.

Colcoction commented Jun 29, 2018

Take LanderBeeuwsaert's solution (by downloading html2canvas.js so you can edit its code like they did) and replace

if (source.width/destination.width > source.height/destination.height) {


if (source.width/destination.width < source.height/destination.height) {

That should get you your desired results. It worked for me, at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment