sanity-io / image-url

Tools to generate image urls from Sanity content
https://www.sanity.io/docs/presenting-images#mY9Be3Ph
MIT License
67 stars 23 forks source link

Bug / feature request: Allow desimal in width/height in imagebuilder #50

Open predbjorn opened 4 years ago

predbjorn commented 4 years ago

I had a problem showing pictures on some devices because I sent a number with decimal to width. It was so hard to debug because I couldn't reproduce the error anywhere. This was my code:

imageUrlBuilder(sanityClient) .image(this.state.sanity.mainImage) .width(PixelRatio.getPixelSizeForLayoutSize(width)) .height(PixelRatio.getPixelSizeForLayoutSize(300)) .fit('crop') .url();

It would be awesome if it did a Math.round(with) or something like that in the library.. So hard to debug if you get the error

My solution:

imageUrlBuilder(sanityClient) .image(this.state.sanity.mainImage) .width(Math.round(PixelRatio.getPixelSizeForLayoutSize(width))) .height(Math.round(PixelRatio.getPixelSizeForLayoutSize(300))) .fit('crop') .url();