File: import_export.rb

package info (click to toggle)
ruby-rmagick 2.13.1-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,524 kB
  • sloc: ansic: 16,755; ruby: 9,730; sh: 14; makefile: 12
file content (31 lines) | stat: -rw-r--r-- 821 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
29
30
31
#
# Demonstrate the export_pixels and import_pixels methods.
#

require 'RMagick'
include Magick

puts <<END_INFO

This example demonstrates the export_pixels and import_pixels methods
by copying an image one row at a time. The result is an copy that
is identical to the original.

END_INFO

img = Image.read(File.join(File.dirname(__FILE__), '../doc/ex/images/Gold_Statue.jpg')).first
copy = Image.new(img.columns, img.rows);

begin
    img.rows.times { |r|
        scanline = img.export_pixels(0, r, img.columns, 1, "RGB");
        copy.import_pixels(0, r, img.columns, 1, "RGB", scanline);
        }
rescue NotImplementedError
    $stderr.puts "The export_pixels and import_pixels methods are not supported" +
                 " by this version of ImageMagick/GraphicsMagick"
    exit
end

copy.write("copy.gif")
exit