Module: Cooltrainer::DistorteD::Technology::Vips::Save

Included in:
Molecule::Font, Molecule::SVG, Molecule::Text, Cooltrainer::DistorteD::Technology::Vips
Defined in:
lib/distorted/modular_technology/vips/save.rb

Constant Summary collapse

VIPS_SAVERS =

Vips allows us to query supported SAVE types by suffix. There’s a simple relationship between filetype and extension since libvips uses the suffix to pick the Saver module. libvips.github.io/libvips/API/current/VipsForeignSave.html

Loader modules, on the other hand, are picked by sniffing the first few bytes of the file, so a list of file extensions for supported loadable formats won’t always be complete. For example, SVG and PDF are usually supported as loaders (via rsvg and PDFium/Poppler) github.com/libvips/ruby-vips/issues/186

irb(main)> Vips.get_suffixes

> [“.csv”, “.mat”, “.v”, “.vips”, “.ppm”, “.pgm”, “.pbm”, “.pfm”,

".hdr", ".dz", ".png", ".jpg", ".jpeg", ".jpe", ".webp", ".tif",
".tiff", ".fits", ".fit", ".fts", ".gif", ".bmp"]
Vips.get_suffixes.map{ |t|
  # A single call to this will return a Set of MIME::Types for a String input
  CHECKING::YOU::OUT(t)
}.reduce { |c,t|
  # Flatten the Set-of-Sets-of-Types into a Set-of-Types
  (c || Set[]).merge(t)
}.keep_if { |t|
  # Filter out any of libvips' supported output Types that aren't
  # actually images (e.g. CSV)
  t.media_type == 'image'
}
OUTER_LIMITS =
VIPS_SAVERS.reduce(Hash[]) { |types,type|
  types[type] = Cooltrainer::DistorteD::Technology::Vips::vips_get_options(
    Vips::vips_foreign_find_save(".#{type.preferred_extension}")
  )
  types
}