module Cooltrainer::DistorteD::Technology::Vips::Save

Constants

OUTER_LIMITS
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"]

Protected Instance Methods

vips_save(dest_root, change) click to toggle source

Generic Vips saver method, optionally handling resizing and cropping. NOTE: libvips chooses a saver (internally) based on the extname of the destination path. TODO: String-buffer version of this method using e.g. Image#jpegsave_buffer

# File lib/distorted/modular_technology/vips/save.rb, line 141
def vips_save(dest_root, change)
  begin
    to_vips_image.write_to_file(change.paths(dest_root).first)
    change.breaks.each { |b|
      ver = to_vips_image.thumbnail_image(
        b.to_int,
        **{:crop => change.crop || :none},
      )
      ver.write_to_file(change.path(dest_root, b))
    }
  rescue Vips::Error => v
    if v.message.include?('No known saver')
      # TODO: Handle missing output formats. Replacements? Skip it? Die?
      return nil
    else
      raise
    end
  end
end