Sha256: 5516d363c73a6002ad8e395fc2d8e0772d2476f7f9a9c573012c6e6343422b7b

Contents?: true

Size: 1.31 KB

Versions: 29

Compression:

Stored size: 1.31 KB

Contents

#! /usr/local/bin/ruby -w

#=======================================================#
# Thanks to Robert Wagner for the idea of allowing a    #
# GravityType instead of the x- and y-offset arguments! #
#=======================================================#

# Demo the use of the GravityType argument to Image#crop.

require 'RMagick'
include Magick

shorts = Image.read('../doc/ex/images/Shorts.jpg').first

regwidth = shorts.columns/2
regheight = shorts.rows/2

mask = Image.new(regwidth, regheight) { self.background_color = 'white'}
mask.opacity = 0.50 * TransparentOpacity

black = Image.new(shorts.columns, shorts.rows) {self.background_color = 'black'}
pairs = ImageList.new

[NorthWestGravity, NorthGravity, NorthEastGravity,
 WestGravity, CenterGravity, EastGravity,
 SouthWestGravity, SouthGravity, SouthEastGravity].each do |gravity|
    pattern = shorts.composite(mask, gravity, OverCompositeOp)
    cropped = shorts.crop(gravity, regwidth, regheight)
    result = black.composite(cropped, gravity, OverCompositeOp)
    result.border_color = "white"
    pairs << pattern
    pairs << result
end

# Montage into a single image
montage = pairs.montage {
    self.geometry = "#{pairs.columns}x#{pairs.rows}+0+0"
    self.tile = "6x3"
    self.border_width = 1
    }
montage.write('crop_with_gravity.miff')
#montage.display




Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
rmagick-2.13.4 examples/crop_with_gravity.rb
rmagick-2.13.3 examples/crop_with_gravity.rb
rmagick-2.13.3.rc1 examples/crop_with_gravity.rb
rmagick-2.13.2 examples/crop_with_gravity.rb
rdp-rmagick-0.0.0 examples/crop_with_gravity.rb
rmagick-2.13.1 examples/crop_with_gravity.rb
rmagick-2.12.2 examples/crop_with_gravity.rb
rmagick-2.12.1 examples/crop_with_gravity.rb
rmagick-2.12.0 examples/crop_with_gravity.rb
rmagick-2.11.1 examples/crop_with_gravity.rb
rmagick-2.10.0 examples/crop_with_gravity.rb
rmagick-2.11.0 examples/crop_with_gravity.rb
rmagick-2.3.0 examples/crop_with_gravity.rb
rmagick-2.2.2 examples/crop_with_gravity.rb
rmagick-2.2.0 examples/crop_with_gravity.rb
rmagick-2.0.0 examples/crop_with_gravity.rb
rmagick-2.1.0 examples/crop_with_gravity.rb
rmagick-2.4.0 examples/crop_with_gravity.rb
rmagick-2.5.1 examples/crop_with_gravity.rb
rmagick-2.5.2 examples/crop_with_gravity.rb