mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
fix: Ensure resizeImage's canvas has at least 1px of width and height (#2409)
* ensure resizeImage canvas has > 0 width, height * add tests for sliver background images
This commit is contained in:
parent
b09ee30dae
commit
bb9237155c
@ -541,8 +541,8 @@ export class CanvasRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const canvas = (this.canvas.ownerDocument as Document).createElement('canvas');
|
const canvas = (this.canvas.ownerDocument as Document).createElement('canvas');
|
||||||
canvas.width = width;
|
canvas.width = Math.max(1, width);
|
||||||
canvas.height = height;
|
canvas.height = Math.max(1, height);
|
||||||
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
|
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
|
||||||
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
|
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
|
||||||
return canvas;
|
return canvas;
|
||||||
|
BIN
tests/assets/bg-sliver.png
Normal file
BIN
tests/assets/bg-sliver.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 190 B |
@ -9,6 +9,10 @@
|
|||||||
display: block;
|
display: block;
|
||||||
background:url("../../assets/image.jpg") center center;
|
background:url("../../assets/image.jpg") center center;
|
||||||
}
|
}
|
||||||
|
.sliver div {
|
||||||
|
background:url("../../assets/bg-sliver.png") center center;
|
||||||
|
background-size: 650px auto;
|
||||||
|
}
|
||||||
|
|
||||||
.vertical {
|
.vertical {
|
||||||
float: right;
|
float: right;
|
||||||
@ -57,5 +61,8 @@
|
|||||||
<div style='background-size: auto;'></div>
|
<div style='background-size: auto;'></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="container" style="padding: 10px; background-size: contain; background-origin: content-box; background-clip: content-box"></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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user