Skip to content

Commit

Permalink
fix: Ensure resizeImage's canvas has at least 1px of width and height (
Browse files Browse the repository at this point in the history
…#2409)

* ensure resizeImage canvas has > 0 width, height

* add tests for sliver background images
  • Loading branch information
cheapsteak authored Jul 4, 2021
1 parent b09ee30 commit bb92371
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/render/canvas/canvas-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ export class CanvasRenderer {
}

const canvas = (this.canvas.ownerDocument as Document).createElement('canvas');
canvas.width = width;
canvas.height = height;
canvas.width = Math.max(1, width);
canvas.height = Math.max(1, height);
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
return canvas;
Expand Down
Binary file added tests/assets/bg-sliver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions tests/reftests/background/size.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
display: block;
background:url("../../assets/image.jpg") center center;
}
.sliver div {
background:url("../../assets/bg-sliver.png") center center;
background-size: 650px auto;
}

.vertical {
float: right;
Expand Down Expand Up @@ -57,5 +61,8 @@
<div style='background-size: auto;'></div>
</div>
<div class="container" style="padding: 10px; background-size: contain; background-origin: content-box; background-clip: content-box"></div>
<div class="sliver">
<div></div>
</div>
</body>
</html>

0 comments on commit bb92371

Please sign in to comment.