class Utopia::Gallery::ResizeImage

Attributes

method[R]
options[R]
size[R]

Public Class Methods

new(name, size = [800, 800], method = :resize_to_fit, **options) click to toggle source
Calls superclass method Utopia::Gallery::Process::new
# File lib/utopia/gallery/process.rb, line 65
def initialize(name, size = [800, 800], method = :resize_to_fit, **options)
        super(name)
        
        @size = size
        @method = method
        @options = options
end

Public Instance Methods

call(cache) click to toggle source
# File lib/utopia/gallery/process.rb, line 99
def call(cache)
        input_path = cache.input_path
        output_path = cache.output_path_for(self)
        
        return if Process.fresh?(input_path, output_path)
        
        resizer = resizer_for(cache.input_path)
        
        FileUtils.mkdir_p(File.dirname(output_path))
        
        generate_output(resizer, output_path)
ensure
        resizer&.close
end
generate_output(resizer, output_path) click to toggle source
# File lib/utopia/gallery/process.rb, line 87
def generate_output(resizer, output_path)
        if output_image = resizer.send(@method, @size)
                output_image.write_to_file output_path, **@options
        else
                Process.link(resizer.input_path, output_path)
        end
end
relative_path(media) click to toggle source
Calls superclass method Utopia::Gallery::Process#relative_path
# File lib/utopia/gallery/process.rb, line 77
def relative_path(media)
        path = super
        
        if path.match?(/\.(pdf|svg)$/)
                path += ".png"
        end
        
        return path
end
resizer_for(input_path) click to toggle source
# File lib/utopia/gallery/process.rb, line 95
def resizer_for(input_path)
        Vips::Thumbnail::Resizer.new(input_path)
end