legrisch/statamic-graphql-thumbnails 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

legrisch/statamic-graphql-thumbnails

Composer 安装命令:

composer require legrisch/statamic-graphql-thumbnails

包简介

A Statamic CMS GraphQL Addon that provides a convenient thumbnail field on all asset fields.

README 文档

README

This Statamic GraphQL addon provides a thumbnail field on all AssetInterface fields. Either provide the argument name to query by predefined formats or use Just-In-Time thumbnail generation and provide width, height or fit.

Features

  • Predefined thumbnail Formats: Query by name
  • Just-In-Time thumbnail: Query by width, height or fit
  • Control Panel UI to define formats and enable/disable JIT thumbnail generation
  • Permissions for managing GraphQL thumbnail Settings

GraphQL Thumbnails for Statamic CMS

Installation

Run composer require legrisch/statamic-graphql-thumbnails

Setup

After installation, you must visit the control panel to define formats to query for or enable the JIT thumbnail generation.

Usage

Formats Usage

The thumbnail field requires an argument name which resolves to the name of one of your formats.

If formats are defined, you can also directly access a property srcset on the Asset.

asset {
  thumbnail(name: "small")
  srcset
}

yields

"asset": {
  "thumbnail": "http://absolute.url/to/thumbnail-small.jpg",
  "srcset": "http://absolute.url/to/thumbnail-small.jpg 500w, http://absolute.url/to/thumbnail-medium.jpg 1000w",
}

JIT Usage

The thumbnail field requires an argument width or height with an integer. Additionally you may specify the parameter fit. The possible values are: contain, max, fill, stretch, crop, crop_focal with the default being crop_focal.

asset {
  thumbnail(width: 100)
}

yields

"asset": {
  "thumbnail": "http://absolute.url/to/thumbnail-with-100px-width.jpg"
}

Full Examples

Query single thumbnail

query MyQuery {
  entries(collection: "pages") {
    data {
      ... on Entry_Pages_Pages {
        image {
          id
          thumbnail(width: 200)
        }
      }
    }
  }
}

yields

{
  "data": {
    "entries": {
      "data": [
        {
          "image": {
            "id": "assets::20210409232458.jpg",
            "thumbnail": "http://absolute.url/to/thumbnail.jpg"
          }
        }
      ]
    }
  }
}

Query multiple thumbnails

Use GraphQL aliases to query multiple thumbnails:

query MyQuery {
  entries(collection: "pages") {
    data {
      ... on Entry_Pages_Pages {
        image {
          id
          thumbnailSmall: thumbnail(width: 100)
          thumbnailMedium: thumbnail(width: 250)
          thumbnailLarge: thumbnail(width: 500)
          thumbnailSquare: thumbnail(width: 500, height: 200, fit: "crop")
        }
      }
    }
  }
}

yields

{
  "data": {
    "entries": {
      "data": [
        {
          "image": {
            "id": "assets::20210409232458.jpg",
            "thumbnailSmall": "http://absolute.url/to/small/thumbnail.jpg",
            "thumbnailMedium": "http://absolute.url/to/medium/thumbnail.jpg",
            "thumbnailLarge": "http://absolute.url/to/large/thumbnail.jpg",
            "thumbnailSquare": "http://absolute.url/to/square/thumbnail.jpg"
          }
        }
      ]
    }
  }
}

License

This project is licensed under the MIT License.

统计信息

  • 总下载量: 222
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-19