Transforming images using streams

Is there a library for transforming images using streams? Specifically I would like to resize and save images as webp. I’m using the image (Image Install & Configure — image v0.42.0) lib, that does have some streaming, but the methods I want to access won’t accept them. Am I missing something with this lib, or is there an alternative I could use?

Streams in elixir essentially boil down to lazy evaluation. You could always wrap the image api call into some kind of callback.

If you can share some more what you need and trying to do (or how it fails) you might have more luck getting help on that one.

If you can explain more specifically what you’re trying to do, and what the failure is you’re seeing I’ll happily look into it.

After reviewing my work I would like to retract this statement:

I found this example in the docs

"some/image.jpg"
|> Image.open!()
|> Image.resize!(200)
|> Image.stream!(suffix: ".jpg", buffer_size: 5_242_880)
|> ExAws.S3.upload("images", "some_object_name.jpg")
|> ExAws.request()

and with some refactoring it got me where I wanted to be.

In short, I was doing something wrong with the file path, and because of that it wasn’t reachable, so I misinterpreted the errors.

Thanks anyway for the quick responses @LostKobrakai and @kip.

2 Likes

If you need to do this on-the-fly, check out imgproxy

If you put a CDN in front of this, the time to process any image into the desired size and format (webp) is negligible since it will be done only occasionally.

Even if you want to be persisting the transformed image, I would use this.

Glad you’re up and running. And it prompted me to fix that example which should be (and is now on hexdocs.pm):

"some/image.jpg"
|> Image.thumbnail!(200)
|> Image.stream!(suffix: ".jpg", buffer_size: 5_242_880)
|> ExAws.S3.upload("images", "some_object_name.jpg")
|> ExAws.request()
2 Likes