|
4 | 4 |
|
5 | 5 | Fileboost is a Rails gem that provides seamless integration with the Fileboost.dev image optimization service. It offers drop-in replacement helpers for Rails' native image helpers with automatic optimization, HMAC authentication, and comprehensive transformation support for ActiveStorage objects. |
6 | 6 |
|
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [Features](#features) |
| 10 | +- [Installation](#installation) |
| 11 | +- [Configuration](#configuration) |
| 12 | +- [Usage](#usage) |
| 13 | + - [Drop-in Replacement (Recommended)](#drop-in-replacement-recommended) |
| 14 | + - [Manual Helper Method](#manual-helper-method) |
| 15 | + - [URL Generation](#url-generation) |
| 16 | + - [Transformation Options](#transformation-options) |
| 17 | + - [Parameter Aliases](#parameter-aliases) |
| 18 | + - [ActiveStorage Support](#activestorage-support) |
| 19 | + - [ActiveStorage Variants (NEW in v0.2.0)](#activestorage-variants-new-in-v020) |
| 20 | + - [Variant Transformation Mapping](#variant-transformation-mapping) |
| 21 | + - [Combining Variants with Custom Options](#combining-variants-with-custom-options) |
| 22 | + - [Responsive Images](#responsive-images) |
| 23 | +- [Error Handling](#error-handling) |
| 24 | +- [Security](#security) |
| 25 | +- [Development](#development) |
| 26 | +- [Testing](#testing) |
| 27 | +- [Contributing](#contributing) |
| 28 | +- [License](#license) |
| 29 | +- [Support](#support) |
| 30 | + |
7 | 31 | ## Features |
8 | 32 |
|
9 | 33 | - 🚀 **Drop-in replacement** for Rails `image_tag` with zero code changes (NEW in v0.2.0) |
| 34 | +- 🎨 **Full ActiveStorage Variant support** with automatic transformation mapping (NEW in v0.2.0) |
10 | 35 | - 🔒 **Secure HMAC authentication** with Fileboost.dev service |
11 | 36 | - 📱 **ActiveStorage only** - works exclusively with ActiveStorage attachments |
12 | 37 | - 🎛️ **Comprehensive transformations** - resize, quality, format conversion, and more |
@@ -79,13 +104,18 @@ With this enabled, your existing Rails code automatically gets Fileboost optimiz |
79 | 104 | <%= image_tag user.avatar, resize: { w: 300, h: 300 }, alt: "Avatar" %> |
80 | 105 | <%= image_tag post.featured_image, resize: { width: 800, quality: 85 }, class: "hero" %> |
81 | 106 |
|
| 107 | +<!-- ActiveStorage variants work seamlessly --> |
| 108 | +<%= image_tag user.avatar.variant(resize_to_limit: [100, 100]), alt: "Thumbnail" %> |
| 109 | +<%= image_tag post.image.variant(:thumb), alt: "Post thumbnail" %> |
| 110 | +
|
82 | 111 | <!-- Non-ActiveStorage images work exactly as before --> |
83 | 112 | <%= image_tag "/assets/logo.png", alt: "Logo" %> |
84 | 113 | <%= image_tag "https://example.com/image.jpg", alt: "External" %> |
85 | 114 | ``` |
86 | 115 |
|
87 | 116 | **Benefits:** |
88 | 117 | - Zero code changes required for existing ActiveStorage images |
| 118 | +- Full ActiveStorage variant support with automatic transformation mapping |
89 | 119 | - Automatic fallback to Rails behavior for non-ActiveStorage assets |
90 | 120 | - Gradual migration path - enable/disable with single configuration option |
91 | 121 |
|
@@ -167,6 +197,64 @@ Works seamlessly with all ActiveStorage attachment types: |
167 | 197 | <%= fileboost_image_tag post.featured_image.blob, resize: { w: 800 } %> |
168 | 198 | ``` |
169 | 199 |
|
| 200 | +### ActiveStorage Variants (NEW in v0.2.0) |
| 201 | + |
| 202 | +Fileboost now provides full support for ActiveStorage variants with automatic transformation mapping: |
| 203 | + |
| 204 | +```erb |
| 205 | +<!-- Basic variants with automatic transformation mapping --> |
| 206 | +<%= image_tag user.avatar.variant(resize_to_limit: [200, 200]) %> |
| 207 | +<!-- ↓ Automatically becomes: w=200&h=200&fit=scale-down --> |
| 208 | +
|
| 209 | +<%= image_tag post.image.variant(resize_to_fit: [400, 300]) %> |
| 210 | +<!-- ↓ Automatically becomes: w=400&h=300&fit=contain --> |
| 211 | +
|
| 212 | +<%= image_tag hero.banner.variant(resize_to_fill: [800, 400]) %> |
| 213 | +<!-- ↓ Automatically becomes: w=800&h=400&fit=cover --> |
| 214 | +
|
| 215 | +<!-- Complex variants with multiple transformations --> |
| 216 | +<%= image_tag post.image.variant( |
| 217 | + resize_to_limit: [600, 400], |
| 218 | + quality: 85, |
| 219 | + format: :webp |
| 220 | +) %> |
| 221 | +<!-- ↓ Automatically becomes: w=600&h=400&fit=scale-down&q=85&f=webp --> |
| 222 | +
|
| 223 | +<!-- Named variants work seamlessly --> |
| 224 | +<%= image_tag user.avatar.variant(:thumb) %> |
| 225 | +<!-- ↓ Uses predefined variant transformations --> |
| 226 | +``` |
| 227 | + |
| 228 | +#### Variant Transformation Mapping |
| 229 | + |
| 230 | +Fileboost automatically maps ActiveStorage variant transformations to optimized URL parameters: |
| 231 | + |
| 232 | +| ActiveStorage Variant | Fileboost Parameters | Description | |
| 233 | +|----------------------|---------------------|-------------| |
| 234 | +| `resize_to_limit: [w, h]` | `w=W&h=H&fit=scale-down` | Resize within bounds, preserving aspect ratio | |
| 235 | +| `resize_to_fit: [w, h]` | `w=W&h=H&fit=contain` | Resize to fit exactly, with letterboxing if needed | |
| 236 | +| `resize_to_fill: [w, h]` | `w=W&h=H&fit=cover` | Resize and crop to fill exactly | |
| 237 | +| `resize_and_pad: [w, h]` | `w=W&h=H&fit=pad` | Resize with padding | |
| 238 | +| `quality: 85` | `q=85` | JPEG/WebP quality (1-100) | |
| 239 | +| `format: :webp` | `f=webp` | Output format | |
| 240 | +| `rotate: "-90"` | `r=-90` | Rotation in degrees | |
| 241 | + |
| 242 | +#### Combining Variants with Custom Options |
| 243 | + |
| 244 | +You can combine variant transformations with additional Fileboost options: |
| 245 | + |
| 246 | +```erb |
| 247 | +<!-- Variant transformations + additional options --> |
| 248 | +<%= image_tag user.avatar.variant(resize_to_limit: [200, 200]), |
| 249 | + resize: { blur: 5, brightness: 110 } %> |
| 250 | +<!-- ↓ Combines variant params with additional blur and brightness --> |
| 251 | +
|
| 252 | +<!-- Override variant parameters --> |
| 253 | +<%= image_tag post.image.variant(resize_to_limit: [400, 300]), |
| 254 | + resize: { w: 500 } %> |
| 255 | +<!-- ↓ Uses h=300&fit=scale-down from variant, but overrides width to 500 --> |
| 256 | +``` |
| 257 | + |
170 | 258 | ### Responsive Images |
171 | 259 |
|
172 | 260 | Generate multiple sizes for responsive designs: |
|
0 commit comments