naqvis / crystal-vips

Crystal bindings for the libvips image processing library.
MIT License
41 stars 5 forks source link

Add support for AVIF #11

Closed Sija closed 8 months ago

Sija commented 8 months ago

SSIA

naqvis commented 8 months ago

AVIF is supported by libvips starting from version v8.8.0, so if you are using version above that, you should be able to invoke operations to work on avif format.

For simple image conversion, below snippet works.

im = Vips::Image.new_from_file("input.jpg")
im.write_to_file("output.avif")
Sija commented 8 months ago

Great, thanks for the clarification! My use case though requires getting the buffer instead of writing to a file, how can I do this?

naqvis commented 8 months ago

My use case though requires getting the buffer instead of writing to a file, how can I do this?

You can use Vips::Target in this case.

im = Vips::Image.new_from_file("test.jpg")
target = Vips::Target.new_to_memory
im.write_to_target(target, "%.avif")
bytes = target.blob # bytes is Slice containing all of the image data
.....
Sija commented 8 months ago

Works like a charm, thanks! ❤️