Sha256: c3259e3a1bd27c27aee5af1c77a64727132ae18a9db558c1a221e422a2a9f5d1

Contents?: true

Size: 790 Bytes

Versions: 9

Compression:

Stored size: 790 Bytes

Contents

#!/usr/local/bin/ruby -w
require 'RMagick'

# Demonstrate the Image#crop method

img = Magick::Image.read('images/Flower_Hat.jpg')[0]

# Crop the specified rectangle out of the img.
chopped = img.crop(23, 81, 107, 139)

# Go back to the original and highlight the area
# corresponding to the retained rectangle.
rect = Magick::Draw.new
rect.stroke('transparent')
rect.fill('white')
rect.fill_opacity(0.25)
rect.rectangle(23, 81, 107+23, 139+81)
rect.draw(img)

img.write('crop_before.png')

# Create a image to use as a background for
# the "after" image.
bg = Magick::Image.new(img.columns, img.rows) {self.background_color="none"}

# Composite the the "after" (chopped) image on the background
bg = bg.composite(chopped, 23, 81, Magick::OverCompositeOp)

bg.write('crop_after.png')

exit

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rmagick-2.13.4 doc/ex/crop.rb
rmagick-2.13.3 doc/ex/crop.rb
rmagick-2.13.3.rc1 doc/ex/crop.rb
rmagick-2.13.2 doc/ex/crop.rb
rdp-rmagick-0.0.0 doc/ex/crop.rb
rmagick-2.13.1 doc/ex/crop.rb
rmagick-2.12.2 doc/ex/crop.rb
rmagick-2.12.1 doc/ex/crop.rb
rmagick-2.12.0 doc/ex/crop.rb