govips icon indicating copy to clipboard operation
govips copied to clipboard

FromBytes to create an image from an RGB []byte?

Open pwaller opened this issue 3 years ago • 2 comments

Hi, Thanks for this project!

Is there a way to make an image given an RGB byte array? I've studied the API and looked through the issue tracker but didn't see any way to achieve this. Thanks!

pwaller avatar Sep 25 '21 11:09 pwaller

I see that the relevant C API is vips_image_new_from_memory, which was exposed via NewImageFromNativeImage in https://github.com/davidbyttow/govips/pull/79. So clearly it's possible to do this for an RGBA image by making a native image.NRGBA (https://pkg.go.dev/image#NRGBA), which is fine if you have an alpha channel. In my case I don't and it would be inconvenient to have to materialise it. It would be nice to have a way of calling vips_image_new_from_memory(..., bands=3), but I guess this requires some implementation work. Please correct me if I'm wrong.

pwaller avatar Sep 25 '21 15:09 pwaller

Hey @pwaller I believe you're on the right track, although I didn't check the source code to verify how much is implemented. Govips can probably handle your use case but if you're looking for native connections with existing Go image libraries and creating new images from byte arrays, other libraries might scratch that itch better. In other use cases such as transforming images from one format to another, govips really shines.

A PR for the above changes (alongside docs and tests of course) would be greatly appreciated and speedily reviewed!

tonimelisma avatar Sep 26 '21 20:09 tonimelisma