Getting started

Integration & migration

Image & video API

DAM user guide

API overview

Account

Ruby

ImageKit integration for Ruby and Ruby on Rails applications with support for image/video transformations, URL generation, and file uploads.


ImageKit provides comprehensive Ruby support through two packages designed for different use cases in the Ruby ecosystem:

Ruby SDK

The ImageKit Ruby SDK is a complete Ruby library for integrating ImageKit's media API. It provides:

  • URL generation with transformations for images and videos
  • File upload management through ImageKit's REST API
  • Signed URLs for secure content delivery
  • Helper methods for authentication and responsive images
  • Type safety with comprehensive RBI (Sorbet) and RBS definitions

The SDK is built on Ruby's standard net/http library with connection pooling, supports Ruby 3.2.0+, and ships with complete YARD documentation.

Installation:

Copy
gem "imagekitio"

Documentation:

Ruby on Rails Gem

The ImageKit Rails gem builds on top of the Ruby SDK to provide Rails-specific integrations:

  • View helpers (ik_image_tag, ik_video_tag) for responsive images and videos
  • Active Storage service for storing uploads in ImageKit
  • Automatic responsive images with srcset generation
  • Seamless integration with Rails asset pipeline and ERB templates

The Rails gem handles common Rails patterns like form uploads, model attachments, and view rendering with transformations.

Installation:

Copy
gem "imagekitio"
gem "imagekitio-rails"

Documentation:

Use Cases

Plain Ruby Applications

Use the Ruby SDK for:

  • Non-Rails Ruby applications (Sinatra, Hanami, etc.)
  • Background job processors
  • Command-line tools and scripts
  • Custom integrations where you need direct API access

Example:

Copy
require 'imagekitio'

client = Imagekitio::Client.new(
  private_key: ENV['IMAGEKIT_PRIVATE_KEY']
)

# Upload a file
response = client.files.upload(
  file: Pathname('/path/to/image.jpg'),
  file_name: 'image.jpg'
)

# Generate URL with transformations
url = client.helper.build_url({
  src: '/default-image.jpg',
  url_endpoint: 'https://ik.imagekit.io/your_imagekit_id',
  transformation: [{ width: 400, height: 300, quality: 80 }]
})

Ruby on Rails Applications

Use the Rails gem for:

  • Full-stack Rails applications
  • Active Storage integration
  • View helpers for images and videos
  • Form uploads with model attachments

Example:

Copy
<%# app/views/products/show.html.erb %>
<%= ik_image_tag(@product.featured_image, 
  transformation: [{ width: 800, height: 600, crop: 'at_max' }],
  sizes: '(max-width: 768px) 100vw, 800px',
  alt: @product.name
) %>

Key Features

URL Generation and Transformations

Both packages support ImageKit's complete transformation API:

  • Image resizing, cropping, and format conversion
  • Quality optimization and format auto-detection
  • Effects (blur, grayscale, rotation, etc.)
  • Text and image overlays
  • Chained transformations
  • AI-powered transformations (background removal, upscaling)

File Management

Upload files to ImageKit through the Ruby SDK's file management API or through Rails Active Storage integration:

Copy
# Direct upload with Ruby SDK
client.files.upload(file: File.read('image.jpg'), file_name: 'image.jpg')

# Rails Active Storage
user.avatar.attach(params[:avatar])
# Automatically stored in ImageKit

Secure Delivery

Generate signed URLs for private content with expiration times:

Copy
# Ruby SDK
url = client.helper.build_url({
  src: '/private-image.jpg',
  signed: true,
  expires_in: 3600
})

# Rails view helper
<%= ik_image_tag('/private-image.jpg', signed: true, expires_in: 3600) %>

Additional Resources