Skip to content
Browse files

1.9 support for RGBA conversion

  • Loading branch information...
1 parent a8e6609 commit 8793420638451dd9c348dc589a46020c14927131 @aberant committed
Showing with 6 additions and 1 deletion.
  1. +6 −1 lib/spittle/image_data.rb
View
7 lib/spittle/image_data.rb
@@ -54,8 +54,13 @@ def fill_to_height( desired_height )
def to_rgba( alpha_value=0 )
return self if pixel_width == RGBA_WIDTH
+ # so ruby 1.9 has different ideas then 1.8 on how Enumerable should work
+ # 1.9 returns Enumerable object if no block given
+ # 1.8 complains if no block, unless using enum_x methods
+ slice_method = (RUBY_VERSION.include?( "1.9" )) ? :each_slice : :enum_slice
+
rgba_data = @data.map do |row|
- pixels = row.enum_slice( RGB_WIDTH )
+ pixels = row.send( slice_method, RGB_WIDTH )
pixels.inject([]){|result, pixel| result + pixel + [alpha_value] }
end

0 comments on commit 8793420

Please sign in to comment.
Something went wrong with that request. Please try again.