File: import_export.rb

package info (click to toggle)
ruby-rmagick 6.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 8,232 kB
  • sloc: cpp: 19,563; ruby: 17,147; sh: 88; javascript: 36; makefile: 13
file content (24 lines) | stat: -rw-r--r-- 575 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
# Demonstrate the export_pixels and import_pixels methods.
#

require 'rmagick'

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 = Magick::Image.read('../doc/ex/images/Gold_Statue.jpg').first
copy = Magick::Image.new(img.columns, img.rows)

img.rows.times do |r|
  scanline = img.export_pixels(0, r, img.columns, 1, 'RGB')
  copy.import_pixels(0, r, img.columns, 1, 'RGB', scanline)
end

copy.write('copy.gif')
exit