lib/carrierwave/processing/mini_magick.rb in carrierwave-3.0.7 vs lib/carrierwave/processing/mini_magick.rb in carrierwave-3.1.0.beta

- old
+ new

@@ -77,10 +77,14 @@ end def resize_and_pad(width, height, background=:transparent, gravity='Center') process :resize_and_pad => [width, height, background, gravity] end + + def crop(left, top, width, height) + process :crop => [left, top, width, height] + end end ## # Changes the image encoding format to the given format # @@ -204,9 +208,34 @@ def resize_and_pad(width, height, background=:transparent, gravity='Center', combine_options: {}, &block) width, height = resolve_dimensions(width, height) minimagick!(block) do |builder| builder.resize_and_pad(width, height, background: background, gravity: gravity) + .apply(combine_options) + end + end + + ## + # Crop the image to the contents of a box positioned at [left] and [top], with the dimensions given + # by [width] and [height]. The original image bottom/right edge is preserved if the cropping box falls + # outside the image bounds. + # + # === Parameters + # + # [left (integer)] left edge of area to extract + # [top (integer)] top edge of area to extract + # [width (Integer)] width of area to extract + # [height (Integer)] height of area to extract + # + # === Yields + # + # [MiniMagick::Image] additional manipulations to perform + # + def crop(left, top, width, height, combine_options: {}, &block) + width, height = resolve_dimensions(width, height) + + minimagick!(block) do |builder| + builder.crop(left, top, width, height) .apply(combine_options) end end ##