elixir-image/image

Image corruption

loics2 opened this issue · 5 comments

I'm trying to process an image and then upload it to S3, and I have some issues with the resulting image stored on a local minio instance. Here's the code for my image processing function:

def process_event_poster(bucket, file, entry) do
    output_file = "#{entry.uuid}_thumb.png"

    Image.open!(file)
    |> Image.thumbnail!(500, crop: :center, height: 705)
    |> Image.stream!(suffix: ".png", buffer_size: 5_242_880)
    |> ExAws.S3.upload(bucket, output_file, acl: :public_read, content_type: "image/png")
    |> ExAws.request()
end

bucket is the name of the S3 bucket to use, file and entry are the file path and the entry given by Phoenix consume_uploaded_entries. The file is correctly uploaded, but I can't open it because it's corrupted. It's working correctly when I don't process my image and use ExAws.S3.Upload.file_stream instead of Image.stream!.

Am I doing something wrong?

Thanks for the report and sorry for the inconvenience. Are you able to let me know what the file size of the thumbnailed image? (ie save the image locally and check the size after thumb nailing?). I suspect its related to the thumbnail being less than 5Mib (S3 chunk size) but want to confirm/deny that before I get too far down that path. Any chance you can share the image itself so I can reproduce exactly what is going on?

No action required on your side - I can see the issue (but not yet diagnosed the cause). Working on it now and will report back.

I have published Image version 0.14.1 with the following changelog entry:

Bug Fixes

  • Fix streaming image writes. Previously the stream chunks were being written in reverse order. Closes #19. Thanks to @loics2 for the report.

Sorry for the delay in getting this fixed, thanks for your support and patience. Please reopen is you still see issues.

Oh nice, thanks!

Sorry for the delay in getting this fixed

No problem, I was about to say you were really reactive

Thats kind of you but I set myself a MTTR of 4 hours - unless there is a really good explanation. Definitely didn’t deliver on that this time. But sometimes the day job does just make that impossible.