Progressive JPEG か Baseline JPEG かを判定する

# 準備

`exiftool` を使います。

```shell:
brew install exiftool
```

# サンプル画像
こちらを使います。

- [Download Sample JPG Image for Demo Use](https://sample-videos.com/download-sample-jpg-image.php)

# Progressive JPEG の場合
`Encoding Process` が `Progressive` であることが確認できます。

```shell:
curl -s https://example.com/cdn-cgi/image/width=150,height=150,fit=cover,format=jpeg/https://sample-videos.com/img/Sample-jpg-image-30mb.jpg \
| exiftool -
```

```text:result.txt
ExifTool Version Number         : 12.60
File Size                       : 0 bytes
File Modification Date/Time     : 2023:07:31 11:30:34+09:00
File Access Date/Time           : 2023:07:31 11:30:34+09:00
File Inode Change Date/Time     : 2023:07:31 11:30:34+09:00
File Permissions                : prw-rw----
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Image Width                     : 150
Image Height                    : 150
Encoding Process                : Progressive DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 150x150
Megapixels                      : 0.022
```

```shell:
curl -s https://example.com/cdn-cgi/image/width=3000,height=3000,fit=cover,format=jpeg/https://sample-videos.com/img/Sample-jpg-image-30mb.jpg \
| exiftool -
```

```text:result.txt
ExifTool Version Number         : 12.60
File Size                       : 0 bytes
File Modification Date/Time     : 2023:07:31 11:32:18+09:00
File Access Date/Time           : 2023:07:31 11:32:18+09:00
File Inode Change Date/Time     : 2023:07:31 11:32:18+09:00
File Permissions                : prw-rw----
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Image Width                     : 3000
Image Height                    : 3000
Encoding Process                : Progressive DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 3000x3000
Megapixels                      : 9.0
```

# Baseline JPEG の場合
`Encoding Process` が `Baseline` であることが確認できます。

```shell:
curl -s https://example.com/cdn-cgi/image/width=150,height=149,fit=cover,format=jpeg/https://sample-videos.com/img/Sample-jpg-image-30mb.jpg \
| exiftool -
```

```text:result.txt
ExifTool Version Number         : 12.60
File Size                       : 0 bytes
File Modification Date/Time     : 2023:07:31 11:34:03+09:00
File Access Date/Time           : 2023:07:31 11:34:03+09:00
File Inode Change Date/Time     : 2023:07:31 11:34:03+09:00
File Permissions                : prw-rw----
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Image Width                     : 150
Image Height                    : 149
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 150x149
Megapixels                      : 0.022
```

```shell:
curl -s https://example.com/cdn-cgi/image/width=3000,height=3001,fit=cover,format=jpeg/https://sample-videos.com/img/Sample-jpg-image-30mb.jpg \
| exiftool -
```

```text:result.txt
ExifTool Version Number         : 12.60
File Size                       : 0 bytes
File Modification Date/Time     : 2023:07:31 11:35:34+09:00
File Access Date/Time           : 2023:07:31 11:35:34+09:00
File Inode Change Date/Time     : 2023:07:31 11:35:34+09:00
File Permissions                : prw-rw----
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Image Width                     : 3000
Image Height                    : 3001
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 3000x3001
Megapixels                      : 9.0
```

# 参考

- [Check a JPEG is progressive or baseline | Sing's Log](https://www.paddingleft.com/2018/09/04/check-a-JPEG-is-progressive-or-baseline/)

# 参考： Cloudflare Image Resizing の挙動

- [Progressive JPEG - Supported formats and limitations · Cloudflare Image Optimization docs](https://developers.cloudflare.com/images/image-resizing/format-limitations/#progressive-jpeg)
> While you can use the format=jpeg option to generate images in an interlaced progressive JPEG format, we will fallback to the baseline JPEG format for small and large images specified when:
>
> The area calculated by width x height is less than 150 x 150.
The area calculated by width x height is greater than 3000 x 3000.
For example, a 50 x 50 tiny image is always formatted by baseline-jpeg even if you specify progressive jpeg (format=jpeg).