响应式图片生成器 responsive-image

响应式图片生成器是一个前端开发工具,用于自动生成多分辨率、多格式的图片集,优化网页图片加载性能。该工具支持srcset属性生成、WebP/AVIF现代格式转换、艺术方向裁剪和HTML picture元素标记生成,帮助开发者实现图片响应式设计,提升网站加载速度和用户体验。关键词:响应式图片,图片优化,WebP转换,AVIF格式,srcset,前端性能优化,图片懒加载,艺术方向裁剪。

前端开发 0 次安装 0 次浏览 更新于 2/26/2026

名称: 响应式图片 描述: 生成响应式图片集,包含srcset、WebP/AVIF转换和艺术方向处理 允许使用的工具:

  • 读取
  • 写入
  • 编辑
  • Bash
  • Glob
  • Grep

响应式图片技能

目的

生成响应式图片集,以在不同设备上实现最佳性能,包括srcset变体、现代格式转换和艺术方向处理。

能力

  • 生成多种分辨率的srcset图片变体
  • 转换为WebP和AVIF格式
  • 为不同视口计算艺术方向裁剪
  • 生成picture元素标记
  • 创建响应式图片配置
  • 优化图片性能

目标流程

  • responsive-design.js
  • component-library.js

集成点

  • Sharp用于图片处理
  • ImageMagick用于高级转换
  • libvips用于高性能操作

输入模式

{
  "type": "object",
  "properties": {
    "inputPath": {
      "type": "string",
      "description": "源图片路径"
    },
    "outputPath": {
      "type": "string",
      "description": "输出目录"
    },
    "widths": {
      "type": "array",
      "items": { "type": "number" },
      "default": [320, 640, 960, 1280, 1920]
    },
    "formats": {
      "type": "array",
      "items": { "type": "string" },
      "default": ["webp", "avif", "jpg"]
    },
    "quality": {
      "type": "number",
      "default": 80
    },
    "artDirection": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "breakpoint": { "type": "number" },
          "crop": { "type": "object" }
        }
      }
    },
    "generateMarkup": {
      "type": "boolean",
      "default": true
    }
  },
  "required": ["inputPath"]
}

输出模式

{
  "type": "object",
  "properties": {
    "generatedImages": {
      "type": "array",
      "description": "生成的图片文件列表"
    },
    "srcset": {
      "type": "string",
      "description": "srcset属性值"
    },
    "pictureMarkup": {
      "type": "string",
      "description": "HTML picture元素标记"
    },
    "sizeSavings": {
      "type": "object",
      "description": "文件大小对比"
    }
  }
}

使用示例

const result = await skill.execute({
  inputPath: './hero-image.jpg',
  outputPath: './responsive',
  widths: [320, 640, 960, 1280, 1920],
  formats: ['webp', 'avif', 'jpg'],
  generateMarkup: true
});