AgentSkillsCN

unsplash-image-finder

当您需要从 Unsplash 中查找并优化适用于网页的图片时,可使用此技能。该技能通过 Unsplash API 搜索图片,并提供带有合适参数的优化后 URL。

SKILL.md
--- frontmatter
name: unsplash-image-finder
description: Use this skill when you need to find and optimize images from Unsplash for web pages. This skill searches for images using the Unsplash API and provides optimized URLs with appropriate parameters.

Unsplash Image Finder

This skill helps find and optimize images from Unsplash for web content.

When to Use

Invoke this skill when:

  • Creating web pages that need hero images, thumbnails, or content images
  • User requests images for their website but doesn't provide specific URLs
  • Building landing pages, blog posts, or documentation with visual content

Search Command

Use the existing search script:

bash
node dev-tools/unsplash-search.js "search keyword"

Single Keyword Search

bash
node dev-tools/unsplash-search.js "coffee shop"

Multiple Keywords Search

bash
node dev-tools/unsplash-search.js "technology,innovation,startup"

URL Optimization Parameters

Unsplash URLs should be optimized with the following parameters:

ParameterDescriptionValues
wWidth in pixels400, 800, 1200, 1600, 1920
qQuality (1-100)80 (recommended)
fmFormatwebp (recommended), jpg, png
fitFit modecrop (recommended)

Recommended Width by Usage

UsageWidthExample
Thumbnail400Cards, small previews
Content image800Blog posts, documentation
Large image1200Feature sections
Hero section1600Above-the-fold heroes
Full-width background1920Full-screen backgrounds

Optimized URL Format

code
https://images.unsplash.com/photo-[ID]?ixid=[ID]&ixlib=rb-4.1.0&w=[WIDTH]&q=80&fm=webp&fit=crop

HTML Implementation

When inserting images, always include:

html
<img
  src="[optimized-url]"
  alt="Descriptive alt text"
  loading="lazy"
  decoding="async"
  class="[responsive-classes]"
>

Required Attributes

  • alt: Descriptive text for accessibility
  • loading="lazy": Defer loading for off-screen images
  • decoding="async": Non-blocking image decode

Fallback Protocol

If the search fails, execute in order:

  1. Primary: Try with original keyword
  2. Secondary: Try broader/simpler keyword (e.g., "coffee" instead of "artisanal coffee shop interior")
  3. Tertiary: Ask user for specific image URL or preference
  4. NEVER: Guess or hallucinate Unsplash URLs from training data

Error Handling

If the search script returns an error:

  1. Check that UNSPLASH_ACCESS_KEY is set in .env.local or environment
  2. Try with a different/simpler keyword
  3. Report the error to the user

Environment Setup

The search script requires:

  • Node.js
  • UNSPLASH_ACCESS_KEY environment variable

See .env.local.example for reference.

Example Workflow

  1. Receive request: "Add a hero image for a tech startup page"
  2. Search: node dev-tools/unsplash-search.js "tech startup office"
  3. Get result: Script returns optimized URL
  4. Apply to code:
    html
    <img
      src="https://images.unsplash.com/photo-xxx?w=1600&q=80&fm=webp&fit=crop"
      alt="Modern tech startup office with team collaboration"
      loading="lazy"
      decoding="async"
      class="w-full h-auto object-cover"
    >
    

Important Notes

  • This skill ONLY searches and provides URLs - it does NOT modify files
  • File modifications are handled by Claude Code main conversation
  • Always verify URLs work before using them
  • Respect Unsplash API usage guidelines