nhost / hasura-storage

Storage for Hasura built on top of S3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image transform sometimes malforms the resulting image

Svarto opened this issue · comments

Hi, I noticed that some images get malformed when transforming them with the &w=1080 url adjustments. See this image for example, without any transformation it looks like here:
https://rklttyqwdzlikrmxlvpg.storage.eu-central-1.nhost.run/v1/files/9cb82a28-9119-425f-8e2e-5695b0e92c37
image

But when transforming it with a w=1080, then the image is cut and repeating (from the looks of it):
https://rklttyqwdzlikrmxlvpg.storage.eu-central-1.nhost.run/v1/files/9cb82a28-9119-425f-8e2e-5695b0e92c37?w=1080
image

Any ideas what is going on here?

I almost think 1/5 images display this issue for me, so it's more common than I first thought

Another weird artifact can be seen in this picture, this happens also on some images:
https://rklttyqwdzlikrmxlvpg.storage.eu-central-1.nhost.run/v1/files/57b1480d-391f-478e-973d-50126dcc0c95?w=1080
image

Some more debugging, seems to happen mostly to image/png files and when they are above 10mb in size. Maybe some shortcut is made in the transformation once a file is bigger than a certain limit?

I think you triggered an interesting chain of events. The CDN pulls large files in segments of 20MB using the Range header. Because the CDN doesn't know ahead of the time the size of the file it is always added, which is fine. However, we also forward those headers to S3 (why would we download from S3 a different range the user requested?). Now, because of those two things I just mentioned what I think is happening is that the image transformation is being applied wrongly on a partial image.

This is clearly a bug, I will start looking into this right away.

I merged a fix to your issue. Will be updating your app in a few hours so you can test yourself.

By the way, I'd recommend you to store smaller versions of your images alongside the original ones. Performing image manipulation on such big images is very inefficient compared to the cost of storage so if you plan to serve smaller versions for faster loading times I'd suggest you to store them already with the correct sizer rather than rely on resizing them on the fly.