AgentSkillsCN

cloudinary

在将图片上传至 Cloudinary、生成优化后的图片 URL、通过 Cloudinary MCP 工具管理资产,或为博客、社交卡片或响应式图片配置 Cloudinary 转换时,可使用此技能。

SKILL.md
--- frontmatter
name: cloudinary
version: 1.1.0
description: Use this skill when uploading images to Cloudinary, generating optimized image URLs, managing assets via Cloudinary MCP tools, or configuring Cloudinary transforms for blogs, social cards, or responsive images.
author: William Smith
tags: [cloudinary, images, cdn, optimization, upload, transforms, media]
triggers:
  keywords:
    - upload to cloudinary
    - cloudinary url
    - optimize images
    - image transforms
    - cloudinary upload
    - blog images
    - f_auto q_auto
    - image cdn
  explicit:
    - /cloudinary
tools:
  - Bash
  - Read
  - WebFetch

Cloudinary Image Management

Behavioral Classification

Type: Guided Decision

Directive: ASK, THEN EXECUTE

Ask the user for the target folder, transform preferences, and image source before uploading. Execute the upload and URL generation workflow based on their choices.

Overview

Cloudinary is an image CDN that serves optimized formats (AVIF/WebP) with on-the-fly transforms. This skill covers uploading, URL generation, and asset management for blog images and other media.

Environment Variables

VariableRequiredSensitiveDescription
CLOUDINARY_URLYesYesFull connection string cloudinary://key:secret@cloud_name
CLOUDINARY_CLOUD_NAMENoNoCloud name (extracted from URL if not set)
CLOUDINARY_API_KEYNoYesAPI key (extracted from URL if not set)
CLOUDINARY_API_SECRETNoYesAPI secret (extracted from URL if not set)

Ensure CLOUDINARY_URL is set in your environment before running upload commands. Never echo or log Cloudinary secrets.

URL Transform Reference

Base URL pattern:

code
https://res.cloudinary.com/<cloud_name>/image/upload/<transforms>/<public_id>

Common Transforms

Use CaseTransformsDescription
Blog bodyf_auto,q_auto,w_1200Auto-format, auto-quality, 1200px wide
Mobilef_auto,q_auto,w_600Optimized for mobile viewports
OG / social cardf_auto,q_auto,w_1200,h_630,c_fill1200x630 social card crop
Retina (2x)f_auto,q_auto,w_2400Double resolution for HiDPI
Thumbnailf_auto,q_auto,w_400,h_300,c_fillSmall preview crop
Original(none)Full-size original

Key Transform Parameters

  • f_auto - Serves AVIF/WebP/PNG based on browser Accept header
  • q_auto - Perceptual quality optimization (~40-60% savings). Variants: q_auto:low, q_auto:eco, q_auto:good, q_auto:best
  • w_N - Scale width to N pixels (preserves aspect ratio)
  • h_N - Scale height to N pixels
  • c_fill - Crop to exact dimensions (use with w_ and h_)
  • c_fit - Resize to fit within bounds without cropping
  • g_auto - Auto-detect focal point for cropping
  • dpr_2.0 - Device pixel ratio for responsive images

Upload Workflow

Programmatic Upload (Node.js SDK)

javascript
import { v2 as cloudinary } from 'cloudinary';
// Auto-configures from CLOUDINARY_URL env var

const result = await cloudinary.uploader.upload(filePath, {
  public_id: imageName,
  folder: 'blog/<article-slug>',
  overwrite: true,
  resource_type: 'image',
});
console.log(result.secure_url);

Install: npm install -D cloudinary --save-exact

CLI Upload

bash
# Upload single file
cld uploader upload <file> public_id=<name> folder=blog/<slug>

# Upload directory
cld uploader upload "dir/*.png" folder=blog/<slug>

# List assets in folder
cld search "folder:blog/<slug>" -f public_id -f format -f bytes

Install CLI: pipx install cloudinary-cli

Batch Upload Script Pattern

A reusable upload script should accept a folder slug and a local image directory:

bash
node upload-images.mjs <slug> <image-dir>

The script should:

  1. Read all image files (PNG, JPG, WebP, AVIF) from the directory
  2. Upload each to blog/{slug}/ folder on Cloudinary
  3. Print optimized URLs with f_auto,q_auto,w_1200 transforms
  4. Save a metadata JSON file with public IDs, dimensions, and original sizes

Folder Conventions

Cloudinary PathContent
blog/{slug}/Blog article images
brand/Logos, icons, brand assets
social/Social media cards and banners

Cloudinary MCP Tools

When the cloudinary-asset-mgmt MCP server is configured, these tools are available:

ToolDescription
upload-assetUpload a file to Cloudinary
search-assetsSearch by folder, tags, or metadata
get-asset-detailsGet asset info (dimensions, format, URL)
transform-assetApply transforms to an existing asset
list-imagesList images in account/folder
delete-assetRemove an asset
asset-renameRename an asset's public ID
create-folderCreate a new folder

MCP Upload Example

code
Use the cloudinary upload-asset tool to upload hero.png
to the blog/my-article folder with overwrite enabled.

Astro Integration

Add Cloudinary to your Astro image config if you want Astro to optimize images at build time:

javascript
// astro.config.mjs
image: {
  domains: ['res.cloudinary.com'],
  remotePatterns: [{
    protocol: 'https',
    hostname: 'res.cloudinary.com',
    pathname: '/<cloud_name>/**',
  }],
}

Note: If you prefer Cloudinary's CDN delivery (f_auto, q_auto, edge caching), do NOT add it to image.domains — Astro would re-encode the images locally at build time, defeating Cloudinary's optimizations.

Markdown Usage

markdown
![Alt text](https://res.cloudinary.com/<cloud_name>/image/upload/f_auto,q_auto,w_1200/blog/<slug>/<name>)

For OG images in frontmatter:

yaml
ogImage: "https://res.cloudinary.com/<cloud_name>/image/upload/f_auto,q_auto,w_1200,h_630,c_fill/blog/<slug>/<name>"

Troubleshooting

ProblemFix
401 UnauthorizedVerify CLOUDINARY_URL is set in your environment
Image not loading in AstroAdd res.cloudinary.com to image.domains in astro config, or verify the URL is valid
Wrong quality / too largeUse q_auto:low or q_auto:eco for smaller files
Blurry on retinaUse w_2400 (2x) or dpr_2.0 transform
Upload overwrites existingSet overwrite: false or use a unique slug
CLI cld not foundInstall with pipx install cloudinary-cli
Python mismatch on CLIFix with pipx reinstall cloudinary-cli