Skip to content

Commit 47cf9a8

Browse files
committed
add to_a
image.to_a makes a Ruby array from an image ... handy with stats, for example
1 parent acdf04c commit 47cf9a8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* simplify gemspec [sandstrom]
66
* remove jeweler dependency [John Cupitt]
7+
* add `.to_a` to Image [John Cupitt]
78

89
# Version 1.0.0
910

lib/vips/image.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,21 @@ def [](index)
926926
end
927927
end
928928

929+
# Convert to an Array. This will be very slow for large images.
930+
#
931+
# @return [Array] array of Fixnum
932+
def to_a
933+
ar = Array.new(height)
934+
for y in 0...height
935+
ar[y] = Array.new(width)
936+
for x in 0...width
937+
ar[y][x] = getpoint(x, y)
938+
end
939+
end
940+
941+
return ar
942+
end
943+
929944
# Return the largest integral value not greater than the argument.
930945
#
931946
# @return [Image] floor of image

0 commit comments

Comments
 (0)