画像の変換
変換を使用すると、Cloudflare Images製品の外部に保存されている画像を最適化および操作できます。変換された画像は、Cloudflareのゾーンの1つから配信されます。
画像を変換するには、ゾーンの変換を有効にする必要があります。
画像は、特別にフォーマットされたURLを使用するか、Workersを通じて変換できます。
- JPEG
- PNG
- GIF(アニメーションを含む)
- WebP(アニメーションを含む)
- SVG
- JPEG
- PNG
- GIF(アニメーションを含む)
- WebP(アニメーションを含む)
- SVG
- AVIF
変換は以下を行うことができます:
- JPEGおよびPNG画像をリサイズおよび生成し、オプションでAVIFまたはWebPを生成します。
- アニメーションをGIFまたはアニメーションWebPとして保存します。
- JPEGおよびPNG画像でICCカラープロファイルをサポートします。
- JPEGメタデータを保持します(他のフォーマットのメタデータは破棄されます)。
- GIF/WebPアニメーションの最初のフレームを静止画像に変換します。
Cloudflare Images can deliver SVG files. However, as this is an inherently scalable format ↗, Cloudflare does not resize SVGs.
As such, Cloudflare Images variants cannot be used to resize SVG files. Variants, named or flexible, are intended to transform bitmap (raster) images into whatever size you want to serve them.
You can, nevertheless, use variants to serve SVGs, using any named variant as a placeholder to allow your image to be delivered. For example:
https://imagedelivery.net/<ACCOUNT_HASH>/<SVG_ID>/publicCloudflare recommends you use named variants with SVG files. If you use flexible variants, all your parameters will be ignored. In either case, Cloudflare applies SVG sanitizing to your files.
You can also use image transformations to sanitize SVG files stored in your origin. However, as stated above, transformations will ignore all transform parameters, as Cloudflare does not resize SVGs.
Cloudflare sanitizes SVG files with svg-hush before serving them. This open-source tool developed by Cloudflare is intended to make SVGs as safe as possible. Because SVG files are XML documents, they can have links or JavaScript features that may pose a security concern. As such, svg-hush filters SVGs and removes any potential risky features, such as:
- Scripting: Prevents SVG files from being used for cross-site scripting attacks. Although browsers do not allow scripts in the
<img>tag, they do allow scripting when SVG files are opened directly as a top-level document. - Hyperlinks to other documents: Makes SVG files less attractive for SEO spam and phishing.
- References to cross-origin resources: Stops third parties from tracking who is viewing the image.
SVG files can also contain embedded images in other formats, like JPEG and PNG, in the form of Data URLs ↗. Cloudflare treats these embedded images just like other images that we process, and optimizes them too. Cloudflare does not support SVG files embedded in SVG recursively, though.
Cloudflare still uses Content Security Policy (CSP) headers to disable unwanted features, but filtering acts as a defense-in-depth in case these headers are lost (for instance, if the image was saved as a file and served elsewhere).
svg-hush is open-source. It is written in Rust and can filter SVG files in a streaming fashion without buffering, so it is fast enough for filtering on the fly.
For more information about svg-hush, refer to Cloudflare GitHub repository ↗.
一部の画像フォーマットは他のフォーマットよりも計算時間が長くかかるため、Cloudflareは画像を生成するのにかかる時間とインターネット経由で転送するのにかかる時間の適切なバランスを見つける必要があります。
リサイズリクエストは、Cloudflareが行わなければならないこれらのトレードオフのために、ユーザーが期待するフォーマットで満たされない場合があります。画像はサイズ、変換、コーデックが異なり、これらの異なる側面が使用される圧縮コーデックに影響を与えます。
Cloudflareは要求されたコーデックを選択しようとしますが、最善を尽くす形で運用しており、すべての顧客を満足させるためにシステムが従う必要のある制限があります。
特にAVIFエンコーディングは、他のフォーマットへのエンコーディングよりも桁違いに遅くなる可能性があります。画像が迅速にエンコードできないほど大きい場合、CloudflareはWebPまたはJPEGにフォールバックします。
ハードリミットは処理する最大画像サイズを指します。ソフトリミットは、システムが過負荷のときに存在する制限を指します。
| ファイルフォーマット | 最長辺のハードリミット(幅または高さ) | 最長辺のソフトリミット(幅または高さ) |
|---|---|---|
| AVIF | 1,200ピクセル1 | 640ピクセル |
| その他 | 12,000ピクセル | N/A |
| WebP | N/A | 劣化圧縮の場合は2,560ピクセル; 無劣化圧縮の場合は1,920ピクセル |
1ハードリミットは、画像変換でformat=avifが明示的に使用される場合、1,600ピクセルになります。
すべての画像は70 MB未満でなければなりません。最大画像面積は100メガピクセルに制限されています(例えば、10,000 x 10,000ピクセルの大きさ)。
GIF/WebPアニメーションは、合計で50メガピクセルに制限されています(すべてのフレームのサイズの合計)。これを超えるアニメーションは、変換を適用せずにそのまま通過します。GIFは古いフォーマットであり、非常に非効率的な圧縮を持っていることに注意してください。高解像度のアニメーションは処理が遅くなり、非常に大きなファイルサイズになります。ビデオクリップについては、CloudflareはMP4やWebMなどのビデオフォーマットの使用を推奨しています。
format=jpegオプションを使用してインターレースプログレッシブJPEGフォーマットで画像を生成できますが、以下の条件が指定された小さな画像および大きな画像の場合、ベースラインJPEGフォーマットにフォールバックします:
- 幅×高さで計算された面積が150×150未満の場合。
- 幅×高さで計算された面積が3000×3000を超える場合。
例えば、50×50の小さな画像は、プログレッシブJPEG(format=jpeg)を指定しても常にbaseline-jpegでフォーマットされます。