Saving image to format determined by file extension
vips-ffm provides VImage::writeToTarget which, as far as I understood from libvips documentation itself, should allow to save an image without knowing what the target format will be, and have the library automatically determine it based on the format option (which should actually be the filename suffix, so include the leading ".", according to my testing).
How would one get a byte array out of a VTarget?
vTarget.getUnsafeStructAddress().asByteBuffer()
does not seem to give a byte buffer of the image or it's missing a NUL terminator or has some other issue.
Also relevant:
vips_target_steal ()
The data is NOT automatically null-terminated. [vips_target_putc()](https://www.libvips.org/API/current/VipsTargetCustom.html#vips-target-putc) a '\0' before calling this to get a null-terminated string.
You can't call this after [vips_target_end()](https://www.libvips.org/API/current/VipsTargetCustom.html#vips-target-end), since that moves the data to a blob, and we can't steal from that in case the pointer has been be shared.
The second paragraph implies to me that we should have a VTarget.end() method or the like to get a VBlob ?
Had a look at how other bindings do this - they seem to just expose the underlying blob for access, with a warning about only using it with memory-backed targets, so I've done the same and added VTarget.getBlob to get the VBlob in 0.5.12 🙂
Sample for that: https://github.com/lopcode/vips-ffm/blob/main/sample/src/main/kotlin/vipsffm/VTargetMemorySample.kt#L10
Seems to work so far. Let me do a little bit more testing, then I'll be happy to close this if that's alright with you?
Yep sounds good to me 👍
Checking in to see if I can close this issue now, @JohannesBeranek?
Sorry for the late response, but looks good now, thanks!