Implementing rotate for save_png

This commit is contained in:
Andy Meneely
2014-08-11 22:04:16 -04:00
parent 15d46182dd
commit 41038178ad
5 changed files with 60 additions and 7 deletions
+24 -2
View File
@@ -3,8 +3,30 @@ module Squib
# :nodoc:
# @api private
def save_png(i, dir, prefix)
cairo_context.target.write_to_png("#{dir}/#{prefix}#{i}.png")
def save_png(i, dir, prefix, rotate)
if rotate
surface = rotated_image
else
surface = @cairo_surface
end
write_png(surface, i, dir, prefix)
end
# :nodoc:
# @api private
def rotated_image
rotated_cc = Cairo::Context.new(Cairo::ImageSurface.new(@height, @width) )
rotated_cc.translate(@height * 0.5, @width * 0.5)
rotated_cc.rotate(0.5 * Math::PI)
rotated_cc.translate(@width * -0.5, @height * -0.5)
rotated_cc.set_source(@cairo_surface)
rotated_cc.paint
rotated_cc.target
end
# :nodoc:
# @api private
def write_png(surface, i, dir, prefix)
surface.write_to_png("#{dir}/#{prefix}#{i}.png")
end
end