doc/ex/get_pixels.rb in rmagick-2.13.4 vs doc/ex/get_pixels.rb in rmagick-2.14.0
- old
+ new
@@ -1,7 +1,7 @@
-#! /usr/local/bin/ruby -w
-require 'RMagick'
+#!/usr/bin/env ruby -w
+require 'rmagick'
# Demonstrate partial transparency and the get_pixels and
# store_pixels methods by creating an image that goes from
# full-color on the left to monochrome on the right.
@@ -21,28 +21,27 @@
# elements as there are columns in the image. The first
# element should be TransparentOpacity and each succeeding
# element slightly more opaque than its predecessor.
step = Magick::TransparentOpacity / cols.to_f
opacity_steps = Array.new(cols)
-cols.times { |x|
- opacity_steps[x] = Magick::TransparentOpacity - Integer(x * step)
- if opacity_steps[x] < Magick::OpaqueOpacity
- opacity_steps[x] = Magick::OpaqueOpacity
- end
-}
+cols.times do |x|
+ opacity_steps[x] = Magick::TransparentOpacity - Integer(x * step)
+ if opacity_steps[x] < Magick::OpaqueOpacity
+ opacity_steps[x] = Magick::OpaqueOpacity
+ end
+end
# Get each row of pixels from the mono image.
# Copy the pre-computed opacity values to the pixels.
# Store the pixels back.
-rows.times { |y|
- pixels = grayrocks.get_pixels(0, y, cols, 1)
- pixels.each_with_index { |p,x| p.opacity = opacity_steps[x] }
- grayrocks.store_pixels(0, y, cols, 1, pixels)
-}
+rows.times do |y|
+ pixels = grayrocks.get_pixels(0, y, cols, 1)
+ pixels.each_with_index { |p,x| p.opacity = opacity_steps[x] }
+ grayrocks.store_pixels(0, y, cols, 1, pixels)
+end
# Composite the mono version of the image over the color version.
grayrocks.matte = true
combine = rocks.composite(grayrocks, Magick::CenterGravity, Magick::OverCompositeOp)
#combine.display
combine.write 'get_pixels.jpg'
exit
-