Ruby SDK
+ Pictify
Official Ruby gem for Rails and Ruby applications.
About Integration
The Pictify Ruby gem provides a clean, Ruby-idiomatic interface for image generation. Includes Rails helpers and integrations for seamless use in Rails applications.
Key Capabilities
Rails integration
ActiveJob support
Ruby-idiomatic API
Faraday-based HTTP
Common Use Cases
Rails applications
Background jobs
Admin dashboards
API backends
Integration Guide
Prerequisites
- Ruby 3.0 or higher
- A Pictify account with an API key
- A template created in Pictify
Install the Gem
Add Pictify to your Gemfile or install directly.
# Add to Gemfile
gem 'pictify'
# Then run
bundle install
# Or install directly
gem install pictifyConfigure the Client
Set up Pictify with your API key. In Rails, use an initializer.
# config/initializers/pictify.rb (Rails)
Pictify.configure do |config|
config.api_key = ENV['PICTIFY_API_KEY']
config.timeout = 30 # seconds
end
# Or configure inline (standalone Ruby)
require 'pictify'
client = Pictify::Client.new(api_key: ENV['PICTIFY_API_KEY'])Store your API key in Rails credentials or environment variables.
Generate an Image
Use the render method to generate images from templates.
# Using the global client (after configuration)
result = Pictify.render(
template_id: 'your-template-id',
variables: {
title: 'Hello from Ruby',
subtitle: 'Generated with the Pictify gem',
accent_color: '#667eea'
},
format: :png,
width: 1200,
height: 630
)
puts result.image_url
# => "https://cdn.pictify.io/renders/abc123.png"
# Or using an instance
client = Pictify::Client.new(api_key: ENV['PICTIFY_API_KEY'])
result = client.render(template_id: 'your-template-id', variables: { title: 'Test' })Download Image
Save the generated image to disk or get raw bytes.
# Download as bytes
image_data = Pictify.render(
template_id: 'your-template-id',
variables: { title: 'Download Test' },
download: true
)
# Save to file
File.binwrite('output.png', image_data)
# Or use the convenience method
Pictify.render_to_file(
template_id: 'your-template-id',
variables: { title: 'File Test' },
output_path: 'my-image.png'
)Rails Integration with ActiveJob
Generate images in the background using ActiveJob.
# app/jobs/generate_og_image_job.rb
class GenerateOgImageJob < ApplicationJob
queue_as :default
def perform(post_id)
post = Post.find(post_id)
result = Pictify.render(
template_id: 'blog-og-template',
variables: {
title: post.title,
author: post.author.name,
date: post.published_at.strftime('%B %d, %Y'),
category: post.category.name
}
)
post.update!(og_image_url: result.image_url)
end
end
# Trigger from controller or callback
class PostsController < ApplicationController
def publish
@post.publish!
GenerateOgImageJob.perform_later(@post.id)
end
endUse ActiveJob for any render that doesn't need to block the request.
Batch Processing
Generate multiple images efficiently.
products = Product.where(needs_image: true).limit(100)
results = Pictify.render_batch(
template_id: 'product-card',
items: products.map do |product|
{
variables: {
name: product.name,
price: helpers.number_to_currency(product.price),
image_url: product.photo_url
}
}
end
)
# Update products with generated images
products.each_with_index do |product, i|
product.update!(card_image_url: results[i].image_url)
endView Helper for Rails
Use the included helper to generate image URLs in views.
# In your view (ERB)
<%= pictify_image_tag(
template_id: 'social-card',
variables: { title: @post.title },
width: 1200,
height: 630,
alt: @post.title,
class: 'og-preview'
) %>
# Or just get the URL
<meta property="og:image" content="<%= pictify_url(
template_id: 'og-image',
variables: { title: @post.title }
) %>" />The helper caches URLs by default. Pass cache: false to disable.
Fast Install
Ready to build with Ruby SDK?
Get your API key in seconds and start generating images programmatically.