Imagekit
Build with ImageKit for real-time image optimization and delivery. Use this skill
You are a media specialist who integrates ImageKit into projects. ImageKit is a real-time image and video optimization service with URL-based transformations, automatic format negotiation, and a global CDN — similar to Cloudinary with simpler, usage-based pricing. ## Key Points - Always use `f-auto,q-auto` for automatic format and quality optimization - Use `fo-auto` (focus auto) for smart cropping based on content - Use the URL endpoint as a CDN origin — images are cached globally - Use client-side uploads with server-generated auth tokens - Organize files in folders and use tags for management - Use named transformations for commonly used transform combinations - Serving original unoptimized images — always use `q-auto,f-auto` - Uploading already-transformed images — upload originals, transform via URL - Exposing the private key to the client — use auth parameters for uploads - Not using lazy loading for below-the-fold images - Generating transformation URLs client-side without the SDK — error-prone ## Quick Example ```bash npm install imagekitio-next # For Next.js # or npm install imagekit # Node SDK ```
skilldb get storage-services-skills/ImagekitFull skill: 167 linesImageKit Integration
You are a media specialist who integrates ImageKit into projects. ImageKit is a real-time image and video optimization service with URL-based transformations, automatic format negotiation, and a global CDN — similar to Cloudinary with simpler, usage-based pricing.
Core Philosophy
URL-based transformations
ImageKit transforms images through URL parameters. Append width, height, crop, quality, and format parameters to any image URL. Transformations are processed and cached at the CDN edge on first request.
Automatic optimization
ImageKit's f-auto parameter serves the best format (WebP, AVIF) based on
browser support. Combined with q-auto for quality, it delivers optimized
images without manual format management.
Setup
Install
npm install imagekitio-next # For Next.js
# or
npm install imagekit # Node SDK
Initialize (Node SDK)
import ImageKit from 'imagekit';
const imagekit = new ImageKit({
publicKey: process.env.IMAGEKIT_PUBLIC_KEY!,
privateKey: process.env.IMAGEKIT_PRIVATE_KEY!,
urlEndpoint: process.env.IMAGEKIT_URL_ENDPOINT!, // https://ik.imagekit.io/your_id
});
Next.js provider
import { ImageKitProvider, IKImage, IKUpload } from 'imagekitio-next';
function App({ children }) {
return (
<ImageKitProvider urlEndpoint={process.env.NEXT_PUBLIC_IMAGEKIT_URL_ENDPOINT!}>
{children}
</ImageKitProvider>
);
}
Key Techniques
URL transformations
// Generate transformed URL
const url = imagekit.url({
path: '/posts/hero.jpg',
transformation: [{
width: '800',
height: '400',
crop: 'maintain_ratio',
focus: 'auto',
quality: 'auto',
format: 'auto',
}],
});
// https://ik.imagekit.io/your_id/tr:w-800,h-400,c-maintain_ratio,fo-auto,q-auto,f-auto/posts/hero.jpg
// Thumbnail
const thumb = imagekit.url({
path: '/posts/hero.jpg',
transformation: [{ width: '150', height: '150', crop: 'at_max' }],
});
// Raw URL pattern
// https://ik.imagekit.io/your_id/tr:w-800,h-400/posts/hero.jpg
Upload
// Server-side upload
const result = await imagekit.upload({
file: buffer, // or base64 string, or URL
fileName: 'hero.jpg',
folder: '/posts/',
tags: ['blog', 'hero'],
});
// result.url, result.fileId, result.name
// Client-side upload (get auth params from server)
// API route
export async function GET() {
const authParams = imagekit.getAuthenticationParameters();
return Response.json(authParams);
}
Next.js components
import { IKImage, IKUpload } from 'imagekitio-next';
// Optimized image
function HeroImage({ path }: { path: string }) {
return (
<IKImage
path={path}
transformation={[{ width: '1200', height: '630', crop: 'maintain_ratio', quality: 'auto', format: 'auto' }]}
alt="Hero"
loading="lazy"
/>
);
}
// Upload component
function Uploader({ onSuccess }: { onSuccess: (url: string) => void }) {
return (
<IKUpload
fileName="upload"
folder="/uploads/"
onSuccess={(res) => onSuccess(res.url)}
onError={(err) => console.error(err)}
/>
);
}
File management
// List files
const files = await imagekit.listFiles({ path: '/posts/', limit: 50 });
// Delete
await imagekit.deleteFile(fileId);
// Get file details
const details = await imagekit.getFileDetails(fileId);
Best Practices
- Always use
f-auto,q-autofor automatic format and quality optimization - Use
fo-auto(focus auto) for smart cropping based on content - Use the URL endpoint as a CDN origin — images are cached globally
- Use client-side uploads with server-generated auth tokens
- Organize files in folders and use tags for management
- Use named transformations for commonly used transform combinations
Anti-Patterns
- Serving original unoptimized images — always use
q-auto,f-auto - Uploading already-transformed images — upload originals, transform via URL
- Exposing the private key to the client — use auth parameters for uploads
- Not using lazy loading for below-the-fold images
- Generating transformation URLs client-side without the SDK — error-prone
Install this skill directly: skilldb add storage-services-skills
Related Skills
AWS S3
Build with AWS S3 for object storage. Use this skill when the project needs to
Backblaze B2
Build with Backblaze B2 for low-cost S3-compatible object storage.
Cloudflare R2
Build with Cloudflare R2 for S3-compatible object storage with zero egress fees.
Cloudinary
Build with Cloudinary for image and video management. Use this skill when the
Tigris
Build with Tigris for globally distributed S3-compatible object storage.
Uploadthing
Build with UploadThing for file uploads in Next.js and React. Use this skill when