akash-akya / vix

Elixir extension for libvips
MIT License
172 stars 20 forks source link

How to load a specific page from image #168

Closed moski closed 1 month ago

moski commented 1 month ago

We have an ICO image, with 4 different page. We can't find any option to load a specific page. I can see from the C binding that

ERL_NIF_TERM nif_image_new_from_file(ErlNifEnv *env, int argc,
                                     const ERL_NIF_TERM argv[])

Takes arguments, but there is no way to pass page into new_from_file.

For example, in the Ruby version, you can do:

Vips::Image.new_from_file(@path, page: page)

Sample image: https://149426355.v2.pressablecdn.com/wp-content/themes/sixcolors/images/favicon.ico

akash-akya commented 1 month ago

Hi @moski, you can pass loader option as a suffix to the path:

{:ok, img} = Vix.Vips.Image.new_from_file("~/Downloads/favicon.ico[page=3]")

I'll add support for additional keyword list argument too

moski commented 1 month ago

Like magic, works 100%.

Thank you for the fast reply and thank you for the amazing library. I've also noticed, that ico format doesn't work with PRECOMPILED_NIF_AND_LIBVIPS. I had to use VIX_COMPILATION_MODE=PLATFORM_PROVIDED_LIBVIPS

Maybe it's worth to add it to the docs as well.

akash-akya commented 1 month ago

Thanks.

Yeah, precompiled libvips only supports few formats. Formats are mentioned here, but I guess it is not easy to spot with all other details. I'll update the docs