File: chop.rb

package info (click to toggle)
ruby-rmagick 6.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,232 kB
  • sloc: cpp: 19,563; ruby: 17,147; sh: 88; javascript: 36; makefile: 13
file content (28 lines) | stat: -rw-r--r-- 756 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'rmagick'

# Demonstrate the Image#chop method

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

# Chop the specified rectangle out of the img.
chopped = img.chop(0, img.rows / 2, img.columns / 2, img.rows)

# Make a "before" image by highlighting the chopped area.
gc = Magick::Draw.new
gc.fill('white')
gc.stroke('transparent')
gc.fill_opacity(0.25)
gc.rectangle(0, img.rows / 2, img.columns / 2, img.rows)
gc.draw(img)

img.write('chop_before.jpg')

# Create a image to use as a background for
# the after image. Make the chopped image the
# same size as before the chop.
bg = Magick::Image.new(img.columns, img.rows)

chopped = bg.composite(chopped, Magick::NorthEastGravity, Magick::OverCompositeOp)

chopped.write('chop_after.jpg')
exit