Ruby SDK

Install the orshot gem, then call render_from_template with a template ID and modifications.

Updated

Installation#

Add this line to your application's Gemfile:

Ruby
gem 'orshot'

And then execute:

Shell
bundle install

Or install it yourself as:

Shell
gem install orshot

Initialise#

Ruby
require 'orshot'

client = Orshot::Client.new('YOUR_ORSHOT_API_KEY')

render_from_studio_template#

Render from a custom Studio template. Supports image, PDF, video generation and publishing to social accounts.

Generate Image#

Ruby
response = client.render_from_studio_template({
  'template_id' => 1234,
  'modifications' => {
    'title' => 'Orshot Studio',
    'description' => 'Generate images from custom templates',
  },
  'response' => { 'type' => 'url', 'format' => 'png', 'scale' => 2 },
})
JavaScript
{
  "data": {
    "content": "https://storage.orshot.com/.../image.png",
    "format": "png",
    "type": "url",
    "responseTime": 3550.43
  }
}

Generate PDF#

Ruby
response = client.render_from_studio_template({
  'template_id' => 1234,
  'modifications' => { 'title' => 'Invoice #1234' },
  'response' => { 'type' => 'url', 'format' => 'pdf' },
  'pdf_options' => {
    'margin' => '20px',
    'range_from' => 1,
    'range_to' => 2,
    'color_mode' => 'rgb',
    'dpi' => 300,
  },
})

Generate Video#

Ruby
response = client.render_from_studio_template({
  'template_id' => 1234,
  'modifications' => {
    'videoElement' => 'https://example.com/custom-video.mp4',
    'videoElement.trimStart' => 0,
    'videoElement.trimEnd' => 10,
  },
  'response' => { 'type' => 'url', 'format' => 'mp4' },
  'video_options' => {
    'trim_start' => 0,
    'trim_end' => 20,
    'muted' => false,
    'loop' => true,
  },
})

Publish to Social Accounts#

Ruby
response = client.render_from_studio_template({
  'template_id' => 1234,
  'modifications' => { 'title' => 'Check out our latest update!' },
  'response' => { 'type' => 'url', 'format' => 'png' },
  'publish' => {
    'accounts' => [1, 2],
    'content' => 'Check out our latest design!',
  },
})
# response['publish'] => [{ 'platform' => 'twitter', 'username' => 'acmehq', 'status' => 'published' }, ...]

Schedule a Post#

Ruby
response = client.render_from_studio_template({
  'template_id' => 1234,
  'modifications' => { 'title' => 'Scheduled post' },
  'response' => { 'type' => 'url', 'format' => 'png' },
  'publish' => {
    'accounts' => [1],
    'content' => 'This will be posted later!',
    'schedule' => { 'scheduled_for' => '2026-04-01T10:00:00Z' },
    'timezone' => 'America/New_York',
  },
})

Parameters#

keyrequireddescription
template_idYesID of the Studio template.
modificationsNoHash of dynamic modifications for the template.
response.typeNobase64, binary, url (Defaults to url).
response.formatNopng, webp, jpg, jpeg, avif, pdf, mp4, webm, mov, mkv, gif (Defaults to png).
response.scaleNoScale of the output (1 = original, 2 = double). Defaults to 1.
response.include_pagesNoPage numbers to render for multi-page templates (e.g. [1, 3]).
response.file_nameNoCustom file name (without extension). Works with url and binary types.
pdf_options.marginNoCSS margin value (e.g. "20px").
pdf_options.range_fromNoStart page number for PDF output.
pdf_options.range_toNoEnd page number for PDF output.
pdf_options.color_modeNorgb or cmyk.
pdf_options.dpiNoDPI for print quality (e.g. 300).
video_options.trim_startNoTrim start time in seconds.
video_options.trim_endNoTrim end time in seconds.
video_options.mutedNoMute audio track.
video_options.loopNoLoop the video.
publish.accountsYes, when publish is setArray of social account IDs from your workspace.
publish.contentNoCaption/text for the social post.
publish.is_draftNotrue to save as draft instead of publishing.
publish.schedule.scheduled_forNoISO date string to schedule the post.
publish.timezoneNoTimezone string (e.g. "America/New_York").
publish.platform_optionsNoPer-account options keyed by account ID.

render_from_template#

Render from a pre-built Orshot template.

Ruby
response = client.render_from_template({
  'template_id' => 'open-graph-image-1',
  'modifications' => {
    'title' => 'Orshot',
    'description' => 'Create Visuals and Automate Image Generation',
  },
  'response_type' => 'url',
  'response_format' => 'png',
})
JavaScript
{
  "data": {
    "content": "https://storage.orshot.com/.../image.png",
    "format": "png",
    "type": "url",
    "responseTime": 3550.43
  }
}
keyrequireddescription
template_idYesID of the template (open-graph-image-1, tweet-image, beautify-screenshot, ...)
modificationsYesModifications for the selected template.
response_typeNobase64, binary, url (Defaults to url).
response_formatNopng, webp, pdf, jpg, jpeg, avif (Defaults to png).

With response_type set to url or base64, read the result like a hash, for example response['data']['content'].

For available templates and their modifications refer Orshot Templates Page


generate_signed_url#

Generate a signed URL for a library template. Opening the URL renders the image.

Ruby
response = client.generate_signed_url({
  'template_id' => 'open-graph-image-1',
  'modifications' => { 'title' => 'Hello World' },
  'expires_at' => 1744276943,
})
JavaScript
{
  "data": {
    "url": "https://api.orshot.com/v1/generate/images?templateId=open-graph-image-1&expiresAt=1744276943&..."
  }
}
keyrequireddescription
template_idYesID of the template (open-graph-image-1, tweet-image, beautify-screenshot, ...)
modificationsYesModifications for the selected template.
expires_atYesUnix timestamp in seconds, or "never" for a URL that does not expire.
render_typeNoOnly images works. Leave it out to use images.

The URL renders a PNG by default. To get another format, add responseFormat inside modifications, for example 'modifications' => { 'title' => 'Hello World', 'responseFormat' => 'jpg' }.


Error Handling#

A failed request raises Orshot::Error with the API's error text.

Ruby
begin
  response = client.render_from_studio_template({
    'template_id' => 1234,
    'modifications' => { 'title' => 'Hello' },
  })
rescue Orshot::Error => e
  puts e.message
end
Was this page helpful?

Ready to automate?

Start rendering images, PDFs and videos from your templates in under 2 minutes. Free plan, no credit card.

Get your API key
  • Image, PDF and video generation via API
  • Visual editor with AI and smart layouts
  • Zapier, Make, MCP and 40+ integrations
  • White-label embed for your own app
  • 100 free credits a month, no credit card required