You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be possible to add class method to Vips that would return an array of supported file formats akin to $ vips -l foreign does? Having such introspection would allow to programmatically decide if for example Vips supports any given format for transformation operation.
If there already exists a way how to get list of Vips' supported extensions, I'm all ears.
The generate_yard method that makes the ruby-vips docs.
You would use GObject::g_type_from_name("VipsForeign") to get the GType for the base class of the file load/save operations (it's just an int), then walk all the subclasses recursively with Vips::vips_type_map looking for non-abstract types. You can instantiate an object of that type and get the text description, a list of the arguments, and the properties of each argument.
You can get things like supported suffixes too, though you'd need to add a little more ffi for that.
I couldn't make access to foreign_class->suffs work via FFI. There isn't existing ForeignClass mapping in ruby-vips and making a simplistic pointer-to-struct didn't work.
@jcupitt I see that you are basing the output on VipsForeignSave. If I compare "save" vs. "load" class extensions, there are some differences (e.g. SVG/PDFs are only supported as input and BMP as output).
As I use Vips for image processing I would be (more) interested in seeing a way to determine what extensions can be processed by Vips at the intake for purpose of populating texts visible to end-user ("Please upload image in ".jpg", ".jpeg" or ".png" formats)/doing pre-emptive validations based on file name.
@tomasc's case also seems to require both "load" and "save" extensions.
Hi @aleksandrs-ledovskis, yes, that's true. libvips uses the suffix to pick savers, so there's a simple relationship between filetype and extension. But loaders are picked by sniffing the first few bytes of the file, so a list of extensions won't always be complete.
I tried swapping it for VipsForeignLoad and I see:
Activity
jcupitt commentedon Oct 25, 2018
Hello @aleksandrs-ledovskis,
You can do this now, though it's a little painful. Have a look at:
https://github.com/libvips/ruby-vips/blob/master/lib/vips/image.rb#L1341
The
generate_yardmethod that makes the ruby-vips docs.You would use
GObject::g_type_from_name("VipsForeign")to get theGTypefor the base class of the file load/save operations (it's just an int), then walk all the subclasses recursively withVips::vips_type_maplooking for non-abstract types. You can instantiate an object of that type and get the text description, a list of the arguments, and the properties of each argument.You can get things like supported suffixes too, though you'd need to add a little more ffi for that.
aleksandrs-ledovskis commentedon Oct 28, 2018
Spent some time digging in
ruby-vips/libvipsand managed to get some PoC codeOn my machine/libvips configuration outputs:
I couldn't make access to
foreign_class->suffswork via FFI. There isn't existingForeignClassmapping inruby-vipsand making a simplistic pointer-to-struct didn't work.tomasc commentedon Feb 10, 2019
@aleksandrs-ledovskis I am using this method here through command-line:
https://github.com/tomasc/dragonfly_libvips/blob/master/lib/dragonfly_libvips.rb#L19
But indeed, would be great to have a method of
ruby-vipsthat outputs such list.add vips_foreign_get_suffixes()
add Vips::get_suffixes
jcupitt commentedon Feb 23, 2019
I had a quick hack and added
get_suffixes:Does that look reasonable? I'll add some tests as well.
tomasc commentedon Feb 23, 2019
Fabulous!
add get_suffixes()
aleksandrs-ledovskis commentedon Feb 24, 2019
@jcupitt I see that you are basing the output on
VipsForeignSave. If I compare "save" vs. "load" class extensions, there are some differences (e.g. SVG/PDFs are only supported as input and BMP as output).As I use Vips for image processing I would be (more) interested in seeing a way to determine what extensions can be processed by Vips at the intake for purpose of populating texts visible to end-user ("Please upload image in ".jpg", ".jpeg" or ".png" formats)/doing pre-emptive validations based on file name.
@tomasc's case also seems to require both "load" and "save" extensions.
jcupitt commentedon Feb 24, 2019
Hi @aleksandrs-ledovskis, yes, that's true. libvips uses the suffix to pick savers, so there's a simple relationship between filetype and extension. But loaders are picked by sniffing the first few bytes of the file, so a list of extensions won't always be complete.
I tried swapping it for
VipsForeignLoadand I see:I don't know how useful that is. It's missing
.icoand.bmp;.jpgis there three times, etc.If you want a list of the available loaders, just walking the types below
VipsForeignLoadmight be simpler.(libvips will load BMP, btw)
Add Base.GetSuffixes()
Add Base.GetSuffixes()