Skip to content
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

Only draws a rectangular portion of the image/canvas in Safari #3

Closed
izkrivera opened this issue May 29, 2019 · 3 comments
Closed

Only draws a rectangular portion of the image/canvas in Safari #3

izkrivera opened this issue May 29, 2019 · 3 comments

Comments

@izkrivera
Copy link

In Safari version 12.1.1 (14607.2.6.1.1) in MacOS 10.14.5 this module draws a partial rectangle of the whole image on the canvas with the filter applied. Removing the ctx.filer = ... renders the whole image again. In Chrome or Firefox there is no issue.

require('context-filter-polyfill');

const drawImagesInCanvas = (canvas, imageDescriptors, includeAll = true) => {
  const ctx = canvas.getContext('2d');
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.filter = 'contrast(1.4) sepia(1) drop-shadow(9px 9px 2px #e81)';
  for (const imageDesc of imageDescriptors) {
    if (!includeAll && !imageDesc.include) { continue; }
    const { image, rotation } = imageDesc;
    const size = imageDesc.resize ? imageSizeThatFitsInSize(image, new Size(canvas.width, canvas.height)) : new Size(image.width, image.height);
    if (rotation > 0) {
      // save the unrotated context of the canvas so we can restore it later
      // the alternative is to untranslate & unrotate after drawing
      ctx.save();

      // move to the center of the canvas
      ctx.translate(canvas.width / 2, canvas.height / 2);

      // rotate the canvas to the specified degrees
      ctx.rotate(rotation * Math.PI / 180);
      ctx.drawImage(image, size.width / -2, size.height / -2, size.width, size.height);

      // we’re done with the rotating so restore the unrotated context
      ctx.restore();
    } else {
      ctx.drawImage(image, 0, 0, size.width, size.height);
    }
  }
};

Screenshot in Chrome: http://www.isaacrivera.com/canvas/chrome.png

Screenshot in Safari: http://www.isaacrivera.com/canvas/safari.png

Please advise!

@izkrivera
Copy link
Author

Apparently there is an issue with the syntax of the drop-shadow example in MDN. Fixing that resolved the issue.

@davidenke
Copy link
Owner

@izkrivera nice to hear :)

@cyrildiagne
Copy link

Hi! I'm also facing this issue. I couldn't find an alternative syntax that works.

drop-shadow(10px 10px 20px #000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants