SVGs with set dimensions return too early
Closed this issue · 5 comments
aldebout commented
When trying to load an svg and explicitely setting its height and weight, the promise returns too early (img.complete === false
)
const img = await loadImages('***.svg', {
height: `100px`,
width: `100px`,
});
I patched it by changing the condition to if (image.naturalWidth && image.complete)
, is this something that we should consider? Do you want me to open a pr when I have the time?
fregante commented
Good point. The conditions should be shuffled as:
if not complete
add listeners
else if naturalWidth
it’s loaded
else
it’s failed
fisker commented
Consider use HTMLImageElement.decode()
(https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode)?
fregante commented
Yes! I'd accept a PR for that.
Sorry I didn't see this earlier
fregante commented
Just use .decode(). I'm deprecating this package.
const img = new Image('***.svg');
img.height = `100px`;
img.width = `100px`;
await img.decode();
fisker commented
Image
doesn't accept src
const img = new Image(100, 100);
img.src = '***.svg';
await img.decode();