Wrapper for puppeteer-img
. Generates screenshot of browser page at a given URL.
Install puppeteer-img
with npm, using the following command:
npm i puppeteer-img -g
Then add the following dependency to your Elixir project
def deps do
[
{:puppeteer_img, "~> 0.1.3"}
]
end
options = [
type: "jpeg"
path: "example.jpeg
]
case PuppeteerImg.generate_image("http://www.example.com", options) do
{:ok, path} -> path # where "path" == final path where generated image is stored.
{:error, error} -> error # where "error" == some error message.
end
options = [
type: "png", # The file type to generate. Options are "jpeg" or "png". Defaults to png.
path: "/screenshots/example.png", # The file path to save the image to.
width: 400, # The width of the browser viewport. Default is 800.
height: 800 # The height of the browser viewport. Default is 600.
scale_factor: 1 # Sets the device pixel scale factor when setting the viewport. Defaults to 1.
]