Skip to content

Instantly share code, notes, and snippets.

@Nephos
Created June 4, 2016 17:50
Show Gist options
  • Save Nephos/9613b2d265dd623824ecd8a2fe0214a9 to your computer and use it in GitHub Desktop.
Save Nephos/9613b2d265dd623824ecd8a2fe0214a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'prawn'
require 'prawn/templates'
module Watermarker
def apply(document, image_path, page_idx = 1, image_opts = {}, text_data = nil, text_opts = {})
document.go_to_page page_idx
document.image image_path, image_opts if image_path
document.draw_text text_data, text_opts if text_data
end
def apply_operations(input, output, operations = {})
Prawn::Document.generate(output, :template => StringIO.new(File.read input)) do |d|
operations.each do |idx, operation|
apply(d, operation[:image_path], idx, operation[:image_opts], operation[:text_data], operation[:text_opts])
end
end
end
extend self
end
=begin
Prawn::Document.generate(output_filename, :template => StringIO.new(File.read input_filename)) do |d|
d.page_count.times do |i|
d.go_to_page i
#d.stroke_line [d.bounds.left,d.bounds.bottom], [d.bounds.right,d.bounds.top]
d.image "a.png", scale: 0.1, at: [420,350]
end
end
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment