fregante/image-promise

SVGs with set dimensions return too early

Closed this issue · 5 comments

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?

Good point. The conditions should be shuffled as:

if not complete
  add listeners
else if naturalWidth
  it’s loaded
else
  it’s failed

Yes! I'd accept a PR for that.

Sorry I didn't see this earlier

Just use .decode(). I'm deprecating this package.

const img = new Image('***.svg');
img.height = `100px`;
img.width = `100px`;
await img.decode();

Image doesn't accept src

const img = new Image(100, 100);
img.src = '***.svg';
await img.decode();