Liquid Snippets by ALSEL
📘 公式リファレンス🔧 リファレンス/フィルター初級

image_url フィルター(画像リサイズ URL 生成)

商品・記事・コレクション画像などを指定サイズにリサイズし、最適化された CDN URL を生成する。幅・高さ、トリミング位置、ファイル形式を指定可能。

用途
商品カードのサムネイル、記事一覧のアイキャッチ、コレクション画像など、異なるサイズで画像を表示するとき。不要な大容量ファイルを避け、ページ速度を改善できる。
設置場所
Liquid 内で `{{ product.image | image_url: width: 450 }}` のように、画像オブジェクトに対して使用する。product、article、collection、image、line_item、variant、country オブジェクトに対応。
注意点
幅(`width`)と高さ(`height`)の少なくとも一つは必須で、両方省略するとエラーが発生する。生成 URL は常に元画像より大きくできない(5760px が上限)。トリミング(`crop`)を指定しない場合は中央(`center`)が適用される。`region` モードで詳細なトリミングをする場合は、`crop_left`、`crop_top`、`crop_width`、`crop_height` パラメータで矩形領域を定義する必要がある。
タグ:imagefilteroptimizationresponsivecdn

仕様

126 行 / json
{
  "category": "media",
  "deprecated": false,
  "deprecation_reason": "",
  "description": "You can use the `image_url` filter on the following objects, as well as their `src` property:\n\n- [`article`](/docs/api/liquid/objects/article)\n- [`collection`](/docs/api/liquid/objects/collection)\n- [`image`](/docs/api/liquid/objects/image)\n- [`line_item`](/docs/api/liquid/objects/line_item)\n- [`product`](/docs/api/liquid/objects/product)\n- [`variant`](/docs/api/liquid/objects/variant)\n- [`country`](/docs/api/liquid/objects/country)\n\n> Caution:\n> You need to specify either a [`width`](/docs/api/liquid/filters/image_url#image_url-width) or\n> [`height`](/docs/api/liquid/filters/image_url#image_url-height) parameter. If neither are specified, then an error is returned.\n\n> Note:\n> Regardless of the specified dimensions, an image can never be resized to be larger than its original dimensions.",
  "parameters": [
    {
      "description": "How the image should be cropped to match the desired dimensions.",
      "name": "crop",
      "positional": false,
      "required": false,
      "types": [
        "string"
      ]
    },
    {
      "description": "The file format for the image.",
      "name": "format",
      "positional": false,
      "required": false,
      "types": [
        "string"
      ]
    },
    {
      "description": "The padding color, if the provided image is smaller than the requested dimensions.",
      "name": "pad_color",
      "positional": false,
      "required": false,
      "types": [
        "string"
      ]
    },
    {
      "description": "The desired image width, in pixels.",
      "name": "width",
      "positional": false,
      "required": true,
      "types": [
        "number"
      ]
    },
    {
      "description": "The desired image height, in pixels.",
      "name": "height",
      "positional": false,
      "required": true,
      "types": [
        "number"
      ]
    }
  ],
  "return_type": [
    {
      "type": "string",
      "name": "",
      "description": "",
      "array_value": ""
    }
  ],
  "examples": [
    {
      "name": "",
      "description": "",
      "syntax": "",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product | image_url: width: 450 }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "width",
      "description": "Specify the width of the image up to a maximum of `5760px`. If only the width is specified, then the height is automatically calculated based on the image's dimensions.\n",
      "syntax": "variable | image_url: width: number",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product | image_url: width: 450 }}",
      "parameter": true,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "height",
      "description": "Specify the height of the image up to a maximum of `5760px`. If only the height is specified, then the width is automatically calculated based on the image's dimensions.\n",
      "syntax": "variable | image_url: height: number",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product | image_url: height: 450 }}",
      "parameter": true,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "crop",
      "description": "Specify which part of the image to show if the specified dimensions result in an aspect ratio that differs from the original. You can use the following values:\n\n- `top`\n- `center`\n- `bottom`\n- `left`\n- `right`\n- `region`\n\nThe default value is `center`.\n\nWhen using the `region` crop mode, the starting point for the crop is defined by `crop_left` and `crop_top` and extends to the `crop_width` and `crop_height`.\nOptionally, to resize the region extracted by the crop, use the `width` and `height` parameters.\n\n> Note:\n> Country flags are SVG images and can only be cropped if a value for `format`\n> is also provided.\n",
      "syntax": "variable | image_url: crop: string",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product | image_url: width: 400, height: 400, crop: 'bottom' }}\n\n{{ product | image_url: crop: 'region', crop_left: 32, crop_top: 32, crop_width: 512, crop_height: 512 }}\n\n{{ product | image_url: crop: 'region', width: 100, height: 100, crop_left: 32, crop_top: 32, crop_width: 512, crop_height: 512 }}",
      "parameter": true,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "format",
      "description": "Specify which file format to use for the image. The valid formats are `pjpg` and `jpg`.\n\nIt's not practical to convert a lossy image format, like `jpg`, to a lossless image format, like `png`, so Shopify can do\nonly the following conversions:\n\n- `png` to `jpg`\n- `png` to `pjpg`\n- `jpg` to `pjpg`\n\n> Note:\n> Shopify automatically detects which image formats are supported by the client (e.g. `WebP`, `AVIF`, etc.) and\n> selects a file format for optimal quality and file size. When a format is specified, Shopify takes into account\n> the features (e.g. progressive, alpha channel) of the specified file format when making the final automatic format selection.\n> To learn more, visit https://cdn.shopify.com/.\n",
      "syntax": "variable | image_url: format: string",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product | image_url: width: 450, format: 'pjpg' }}",
      "parameter": true,
      "display_type": "text",
      "show_data_tab": true
    },
    {
      "name": "pad_color",
      "description": "Specify a color to pad the image if the specified dimensions result in an aspect ratio that differs from the original. The color must be in hexadecimal format (`hex3` or `hex6`).\n",
      "syntax": "variable | image_url: pad_color: string",
      "path": "/products/health-potion",
      "raw_liquid": "{{ product | image_url: width: 400, height: 400, pad_color: '000' }}",
      "parameter": true,
      "display_type": "text",
      "show_data_tab": true
    }
  ],
  "summary": "Returns the [CDN URL](/themes/best-practices/performance/platform#shopify-cdn) for an image.",
  "syntax": "variable | image_url: width: number, height: number",
  "name": "image_url"
}

出典・ライセンス

License:
MIT

このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。

関連項目

📘 公式リファレンス🔧 リファレンス/フィルター初級

avatar フィルター(顧客アバター画像HTML生成)

顧客アバターが存在する場合、それを表示する HTML タグを生成するフィルター。customer オブジェクトに対して使用する。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

default_errors フィルター(フォーム送信エラーを日本語化)

form.errors の各エラーコードに対応する既定のエラーメッセージを自動生成するフィルター。フォーム送信時の入力値不正や必須項目空白などのエラーを言語別に出力する。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

date フィルター(日付を指定形式でフォーマット)

日付値を指定されたフォーマット文字列に従って整形する。フォーマット文字列が空の場合は元の値がそのまま返される。入力が日付に変換できない場合も元の値が返される。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

payment_terms フィルター(Shop Pay分割払いバナーを生成)

product フォームまたは cart フォームに対して使用し、Shop Pay の分割払いオプションを表示するための HTML を生成するフィルター。顧客が購入時に分割払いプランを選択できるようにする。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

abs フィルター(数値の絶対値を取得)

負の数を正の数に変換する。数値の絶対値(ゼロからの距離)を返すフィルター。

📁 theme-liquid-docs·MIT·30
📘 公式リファレンス🔧 リファレンス/フィルター初級

append フィルター(文字列の末尾に追加)

文字列の末尾に別の文字列を連結するフィルター。URL パスの結合やテキストの接尾辞追加に使う。

📁 theme-liquid-docs·MIT·30