Class: Utopia::Gallery::ResizeImage
- Defined in:
- lib/utopia/gallery/process.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from Process
Instance Method Summary collapse
- #call(cache) ⇒ Object
- #generate_output(resizer, output_path) ⇒ Object
-
#initialize(name, size = [800, 800], method = :resize_to_fit, **options) ⇒ ResizeImage
constructor
A new instance of ResizeImage.
- #relative_path(media) ⇒ Object
- #resizer_for(input_path) ⇒ Object
Methods inherited from Process
Constructor Details
#initialize(name, size = [800, 800], method = :resize_to_fit, **options) ⇒ ResizeImage
Returns a new instance of ResizeImage.
65 66 67 68 69 70 71 |
# File 'lib/utopia/gallery/process.rb', line 65 def initialize(name, size = [800, 800], method = :resize_to_fit, **) super(name) @size = size @method = method @options = end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
74 75 76 |
# File 'lib/utopia/gallery/process.rb', line 74 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
75 76 77 |
# File 'lib/utopia/gallery/process.rb', line 75 def @options end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
73 74 75 |
# File 'lib/utopia/gallery/process.rb', line 73 def size @size end |
Instance Method Details
#call(cache) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# 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) ⇒ Object
87 88 89 90 91 92 93 |
# 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) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# 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) ⇒ Object
95 96 97 |
# File 'lib/utopia/gallery/process.rb', line 95 def resizer_for(input_path) Vips::Thumbnail::Resizer.new(input_path) end |