timse / srcset-loader

Flexible srcset-loader for webpack
46 stars 14 forks source link

Bug in SVG placeholder size #15

Closed tremby closed 6 years ago

tremby commented 6 years ago

I came across this piece of code:

https://github.com/timse/srcset-loader/blob/61c127efb001fce4414ba4fa9d889fe520ae10c8/src/runtime.js#L18-L23

Whichever way around the aspect ratio is (see #14), this code seems broken.

viewBox is x offset, y offset, width, height.

For height you have 10 * (1 - ratio).

But ratio can be any number greater than zero and less than infinity. If ratio is 2, for example (either a 100x200 or 200x100 image, depending how the ratio is calculated), this will evaluate to a height of -10.

tremby commented 6 years ago

On further examination I found this:

https://github.com/timse/srcset-loader/blob/61c127efb001fce4414ba4fa9d889fe520ae10c8/test/test.js#L213

This will currently fail for any portrait image!