class SrcsetImages::VipsCreateImageVersion
Public Class Methods
call(*_)
click to toggle source
VipsCreateImageVersion
.(source, destination, width: 800, height: 600, …)
# File lib/middleman-srcset_images/vips_create_image_version.rb, line 8 def self.call(*_) new(*_).call end
new(img, destination_path, options = {})
click to toggle source
# File lib/middleman-srcset_images/vips_create_image_version.rb, line 12 def initialize(img, destination_path, options = {}) @source = if img.is_a?(String) || img.is_a?(Pathname) ImageProcessing::Vips.source(img) else img end @destination = destination_path @width = options[:width] @height = options[:height] @crop = !!options[:crop] @quality = options.fetch :quality, 90 end
Public Instance Methods
call()
click to toggle source
# File lib/middleman-srcset_images/vips_create_image_version.rb, line 29 def call img = if @crop @source.resize_to_fill @width, @height, crop: :attention else @source.resize_to_limit @width, @height end processed = img .saver(strip: true, quality: @quality, interlace: true) .call FileUtils.mkdir_p File.dirname(@destination) FileUtils.mv processed, @destination true end