Method: ImageProcessing::MiniMagick.resize_and_pad!
- Defined in:
- lib/image_processing/mini_magick.rb
.resize_and_pad!(image, width, height, background: "transparent", gravity: "Center") {|MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert| ... } ⇒ File, Tempfile
Resize the image to fit within the specified dimensions while retaining the original aspect ratio in the same way as #fill. Unlike #fill it will, if necessary, pad the remaining area with the given color, which defaults to transparent where supported by the image format and white otherwise.
The resulting image will always be exactly as large as the specified dimensions.
By default, the image will be placed in the center but this can be changed via the ‘gravity` option.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/image_processing/mini_magick.rb', line 140 def resize_and_pad!(image, width, height, background: "transparent", gravity: "Center") with_minimagick(image) do |img| img. do |cmd| yield cmd if block_given? cmd.resize "#{width}x#{height}" if background == "transparent" cmd.background "rgba(255, 255, 255, 0.0)" else cmd.background background end cmd.gravity gravity cmd.extent "#{width}x#{height}" end end end |