Method: HTMLCSSToImage#url_to_image

Defined in:
lib/htmlcsstoimage.rb

#url_to_image(url, params = {}) ⇒ Object

Generate a screenshot of a URL

Parameters:

  • url (String)

    The fully qualified URL to a public webpage. Such as htmlcsstoimage.com.

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :css (String)

    The CSS for your image. Gets injected into the webpage.

  • :selector (String)

    A CSS selector for an element on the webpage. We’ll crop the image to this specific element. For example: ‘section#complete-toolkit.container-lg`

  • :ms_delay (Integer)

    The number of milliseconds the API should delay before generating the image. This is useful when waiting for JavaScript. We recommend starting with 500. Large values slow down the initial render time.

  • :device_scale (Double)

    This adjusts the pixel ratio for the screenshot. Minimum: 1, Maximum: 3.

  • :render_when_ready (Boolean)

    Set to true to control when the image is generated. Call ‘ScreenshotReady()` from JavaScript to generate the image. [Learn more](docs.htmlcsstoimage.com/guides/render-when-ready/).

  • :viewport_width (Integer)

    Set the width of Chrome’s viewport. This will disable automatic cropping. Both height and width parameters must be set if using either.

  • :viewport_height (Integer)

    Set the height of Chrome’s viewport. This will disable automatic cropping. Both height and width parameters must be set if using either.

See Also:



116
117
118
119
120
121
# File 'lib/htmlcsstoimage.rb', line 116

def url_to_image(url, params = {})
  body = { url: url }.merge(params).to_json
  options = { basic_auth: @auth, body: body, query: { includeId: true } }

  self.class.post("/v1/image", options)
end