image

画像ファイルのアップロード用フィールドです。サムネイル、アイキャッチ画像、アバターなどに使用します。

基本例

{
  "name": "thumbnail",
  "type": "image",
  "label": "サムネイル"
}

プロパティ

プロパティ必須説明
namestringYesフィールドの識別子
type"image"Yes"image"を指定
labelstringNoCMS上での表示名
notestringNo編集者向けの補足メモ
requiredbooleanNo必須フィールドかどうか
optionsobjectNo画像の制約設定

optionsプロパティ

プロパティ説明
maxSizeBytesnumber最大ファイルサイズ(バイト)
allowedTypesstring[]許可するMIMEタイプ
aspectRatiostringアスペクト比(例: "16:9"

使用例

サムネイル

{
  "name": "thumbnail",
  "type": "image",
  "label": "サムネイル",
  "required": true
}

サイズ制限付き

{
  "name": "coverImage",
  "type": "image",
  "label": "カバー画像",
  "options": {
    "maxSizeBytes": 5242880
  },
  "note": "5MB以下の画像をアップロードしてください"
}

形式制限付き

{
  "name": "photo",
  "type": "image",
  "label": "写真",
  "options": {
    "allowedTypes": ["image/jpeg", "image/png", "image/webp"]
  },
  "note": "JPEG、PNG、WebP形式のみ"
}

アスペクト比指定

{
  "name": "ogImage",
  "type": "image",
  "label": "OGP画像",
  "options": {
    "aspectRatio": "1.91:1",
    "allowedTypes": ["image/jpeg", "image/png"]
  },
  "note": "OGP用の画像(1.91:1)"
}

完全な設定例

{
  "name": "heroImage",
  "type": "image",
  "label": "ヒーロー画像",
  "required": true,
  "options": {
    "maxSizeBytes": 2097152,
    "allowedTypes": ["image/jpeg", "image/png", "image/webp"],
    "aspectRatio": "16:9"
  },
  "note": "2MB以下、16:9の画像をアップロードしてください"
}

アバター

{
  "name": "avatar",
  "type": "image",
  "label": "アバター",
  "options": {
    "maxSizeBytes": 1048576,
    "aspectRatio": "1:1"
  },
  "note": "1MB以下の正方形画像"
}

許可されているMIMEタイプ

pitcmsでデフォルトで許可されているMIMEタイプは以下の5つです。allowedTypesを指定しない場合、これらすべてが許可されます。

MIMEタイプ拡張子説明
image/jpeg.jpg, .jpegJPEG画像
image/png.pngPNG画像
image/gif.gifGIF画像
image/webp.webpWebP画像
image/svg+xml.svgSVG画像

allowedTypesで上記の中から許可する形式を絞り込むことができます。

一般的なファイルサイズ

サイズバイト数
500KB512000
1MB1048576
2MB2097152
5MB5242880
10MB10485760

保存形式

画像のURLが文字列として保存されます。

マークダウン形式:

---
thumbnail: "https://example.com/images/thumbnail.jpg"
---

JSON形式:

{
  "thumbnail": "https://example.com/images/thumbnail.jpg"
}