error transforming image, Framebuffer contains no pixels. When putting decoder into struct
paulm17 opened this issue · comments
Firstly many thanks for open sourcing this library!
I do have an issue however. I'm wanting to read the file only once and pass the decoder and header into a struct for use later on.
The problem that I am having. Is that once an image gets processed the decoder inside the struct gets flushed and I get the error: "error transforming image, Framebuffer contains no pixels".
I have created a simple gist to show what I am doing:
https://gist.github.com/paulm17/4bd17334660101139a973921924a00b3
I really don't want to read the file for every resize at scale. What can I do here?
Thanks
Hi @paulm17
I can think of two ways to handle this
-
You could forego the ImageOps and instead use DecodeTo/Resize/Encoder yourself. You'd DecodeTo a Framebuffer once, then manage the buffers for resize and encoder manually. Some of the docs for that are in the README, but there's no example for how to do this.
-
You could fork the library a bit so that ImageOps instead takes a
[]
ofImageOptions
and[]byte
s. Then internally it would do the work it does, but re-performing each option work item into a new dst buffer. If you go this route, I'd be happy to review a PR to mainline this new functionality.
Hope that helps!
Thanks for taking the time to respond.
I couldn't quite grok the second suggestion, so instead I decided to store the bytes and resupply the decoder on each size. This solves my requirement of not re-reading the file on each size and I'm hoping that reading bytes by the decoder is less intensive on scale.
Anyway, consider this solved.
Thanks!