Class: Utopia::Gallery::ResizeImage

Inherits:
Process
  • Object
show all
Defined in:
lib/utopia/gallery/process.rb

Instance Attribute Summary

Attributes inherited from Process

#name

Instance Method Summary collapse

Methods inherited from Process

#fresh?, #relative_path

Constructor Details

#initialize(name, size = [800, 800], method = :resize_to_fit, **options) ⇒ ResizeImage

Returns a new instance of ResizeImage.



45
46
47
48
49
50
51
# File 'lib/utopia/gallery/process.rb', line 45

def initialize(name, size = [800, 800], method = :resize_to_fit, **options)
	super(name)
	
	@size = size
	@method = method
	@options = options
end

Instance Method Details

#call(cache, locals) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/utopia/gallery/process.rb', line 53

def call(cache, locals)
	output_path = cache.output_path_for(self)
	media = cache.media
	media_path = File.join(cache.media_root, media.path)
	
	return if fresh?(media_path, output_path)
	
	resizer = locals[:resizer] ||= Vips::Thumbnail::Resizer.new(media_path)
	
	FileUtils.mkdir_p(File.dirname(output_path))
	
	if output_image = resizer.send(@method, @size)
		output_image.write_to_file output_path, **@options
	else
		FileUtils.ln(media_path, output_path)
	end
end