document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. background_image = Image.read("canvas:khaki") do
  2.   self.size = "700x700"
  3. end
  4.  
  5. background_image = background_image.first
  6.  
  7. font_size = 100
  8. font_path = "../font.ttf"
  9. width_of_bounding_box = 600
  10. text_to_print = "Hey this is some text!"
  11.  
  12. # Create a new instance of the text wrap helper and give it all the
  13. # info the class needs..
  14. helper = RMagickTextWrapHelper.new(text_to_print, font_size, width_of_bounding_box, font_path)
  15.  
  16. text = Draw.new
  17. text.pointsize = font_size
  18. text.gravity = NorthWestGravity
  19. text.fill = "#B22222"
  20. text.font = font_path
  21.  
  22. # Call the "get_text_with_line_breaks" to get text
  23. # with line breaks where needed
  24. text_wit_line_breaks = helper.get_text_with_line_breaks
  25.  
  26. text.annotate(background_image, 700, 700, 0, 0, text_wit_line_breaks)
  27.  
  28. background_image.write("rmagick-add-text-to-an-image-with-line-breaks.png")
');