Created
March 3, 2016 16:20
-
-
Save lappi-lynx/2af3acb63637d70d2a3c to your computer and use it in GitHub Desktop.
Prawn PDF images with Base64 and StringIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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