Skip to content

Instantly share code, notes, and snippets.

@lappi-lynx
Created March 3, 2016 16:20
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lappi-lynx/2af3acb63637d70d2a3c to your computer and use it in GitHub Desktop.
Save lappi-lynx/2af3acb63637d70d2a3c to your computer and use it in GitHub Desktop.
Prawn PDF images with Base64 and StringIO
def render
pdf = Prawn::Document
pdf.image StringIO.new(Base64.decode64(splitBase64(BASE64_IMAGE_GOES_HERE)[:data])), at: [10, cursor - 50], width: 200, height: 125
end
def splitBase64(uri)
if uri.match(%r{^data:(.*?);(.*?),(.*)$})
return {
type: $1, # "image/png"
encoder: $2, # "base64"
data: $3, # data string
extension: $1.split('/')[1] # "png"
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment