Method: Inkmake::InkFile#temp_rotate_svg

Defined in:
lib/inkmake.rb

#temp_rotate_svg(path, degrees, width, height) ⇒ Object



565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/inkmake.rb', line 565

def temp_rotate_svg(path, degrees, width, height)
  if degrees != 180
    out_width, out_height = height, width
  else
    out_width, out_height = width, height
  end
  file_href = "file://#{path}"
  svg =
    "<?xml version=\"1.0\"?>" +
    "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"#{out_width}\" height=\"#{out_height}\">" +
    "<g>" +
    "<image transform=\"translate(#{out_width/2} #{out_height/2}) rotate(#{degrees})\"" +
    "  width=\"#{width}\" height=\"#{height}\" x=\"#{-width/2}\" y=\"#{-height/2}\"" +
      "  xlink:href=#{file_href.encode(:xml => :attr)} />" +
    "</g>" +
      "</svg>"
    f = Tempfile.new(["inkmake", ".svg"])
    f.write(svg)
    f.flush
    f.seek(0)
    [f, out_width, out_height]
end