lib/chunky_png/canvas/operations.rb in chunky_png-0.8.0 vs lib/chunky_png/canvas/operations.rb in chunky_png-0.9.0
- old
+ new
@@ -54,9 +54,49 @@
def change_mask_color!(new_color)
raise ChunkyPNG::ExpectationFailed, "This is not a mask image!" if palette.opaque_palette.size != 1
pixels.map! { |pixel| (new_color & 0xffffff00) | ChunkyPNG::Color.a(pixel) }
end
+
+ def flip_horizontally
+ self.class.new(width, height).tap do |flipped|
+ for y in 0...height do
+ flipped.replace_row!(height - (y + 1), row(y))
+ end
+ end
+ end
+
+ def flip_vertically
+ self.class.new(width, height).tap do |flipped|
+ for x in 0...width do
+ flipped.replace_column!(width - (x + 1), column(x))
+ end
+ end
+ end
+
+ def rotate_right
+ self.class.new(height, width).tap do |rotated|
+ for i in 0...width do
+ rotated.replace_row!(i, column(i).reverse)
+ end
+ end
+ end
+
+ def rotate_left
+ self.class.new(height, width).tap do |rotated|
+ for i in 0...width do
+ rotated.replace_row!(width - (i + 1), column(i))
+ end
+ end
+ end
+
+ def rotate_180
+ self.class.new(width, height).tap do |flipped|
+ for y in 0...height do
+ flipped.replace_row!(height - (y + 1), row(y).reverse)
+ end
+ end
+ end
protected
def check_size_constraints!(other, offset_x, offset_y)
raise ChunkyPNG::ExpectationFailed, "Background image width is too small!" if width < other.width + offset_x