rubyimagerelative-pathprawn

prawn - import image from URL


I can't seem to figure out how to import an image from an url

To import the images from my localhost I use:

image"./assets/images/img.png"

When I replace the path with an URL it says

`image' : URL not found

Is there a solution for this, or should I create a def that downloads the image and to use the path it returns?


Solution

  • you need to do the following -

    require "open-uri"
    
    Prawn::Document.generate(INSERT_YOUR_PDF_FILENAME_HERE) do 
       image open(INSERT_YOUR_URL_HERE)
    end
    

    Refer to http://rubydoc.info/gems/prawn/0.12.0/frames for more details.