Dataset Viewer
Auto-converted to Parquet Duplicate
file_name
stringclasses
30 values
variant
stringclasses
6 values
seed
int64
1
30
width
int64
384
768
height
int64
384
1.02k
format
stringclasses
5 values
quality
int64
40
95
⌀
bytes
int64
4.21k
289k
bpp
float64
0.11
5.29
ssim
float64
0.94
1
ssim_hair
float64
0.8
1
psnr_y
float64
33.1
99
encode_ms
float64
0.7
448
card_01_clean.png
clean
1
768
1,024
jpeg
50
47,655
0.4848
0.94271
0.90612
33.38
17.8
card_01_clean.png
clean
1
768
1,024
jpeg
60
54,775
0.5572
0.94872
0.92464
34.477
3
card_01_clean.png
clean
1
768
1,024
jpeg
70
65,826
0.6696
0.95577
0.94413
35.969
3.5
card_01_clean.png
clean
1
768
1,024
jpeg
80
84,372
0.8583
0.96412
0.96324
38.162
3.9
card_01_clean.png
clean
1
768
1,024
jpeg
85
99,551
1.0127
0.96931
0.97228
39.726
4.1
card_01_clean.png
clean
1
768
1,024
jpeg
90
126,377
1.2856
0.97643
0.98265
41.908
4.6
card_01_clean.png
clean
1
768
1,024
jpeg
95
183,453
1.8662
0.9877
0.99406
45.83
5.4
card_01_clean.png
clean
1
768
1,024
webp
50
34,016
0.346
0.95857
0.95176
38.029
112.2
card_01_clean.png
clean
1
768
1,024
webp
60
36,856
0.3749
0.96117
0.95922
38.756
41.2
card_01_clean.png
clean
1
768
1,024
webp
70
40,322
0.4102
0.96377
0.96746
39.511
42.2
card_01_clean.png
clean
1
768
1,024
webp
80
51,336
0.5222
0.97091
0.98075
41.318
44.5
card_01_clean.png
clean
1
768
1,024
webp
85
63,952
0.6506
0.97852
0.98805
43.045
47.1
card_01_clean.png
clean
1
768
1,024
webp
90
88,190
0.8971
0.98768
0.9939
45.548
50.7
card_01_clean.png
clean
1
768
1,024
webp
95
126,252
1.2843
0.99555
0.99765
49.627
57.1
card_01_clean.png
clean
1
768
1,024
avif
40
15,691
0.1596
0.95859
0.92968
38.521
255.1
card_01_clean.png
clean
1
768
1,024
avif
50
24,194
0.2461
0.97323
0.96981
41.585
250
card_01_clean.png
clean
1
768
1,024
avif
60
36,966
0.376
0.99116
0.99141
45.654
276.1
card_01_clean.png
clean
1
768
1,024
avif
70
43,276
0.4402
0.99485
0.99579
47.684
295.5
card_01_clean.png
clean
1
768
1,024
avif
80
50,755
0.5163
0.99699
0.99745
49.482
305
card_01_clean.png
clean
1
768
1,024
avif
90
61,672
0.6274
0.99837
0.99866
51.651
362.9
card_01_clean.png
clean
1
768
1,024
png
null
173,583
1.7658
1
1
99
226.7
card_01_clean.png
clean
1
768
1,024
webp_lossless
null
112,296
1.1423
1
1
99
219.4
card_01_clean.png
clean
1
384
512
jpeg
50
11,990
0.4879
0.95842
0.88182
34.916
1
card_01_clean.png
clean
1
384
512
jpeg
60
13,587
0.5529
0.96468
0.90424
35.906
0.9
card_01_clean.png
clean
1
384
512
jpeg
70
15,939
0.6486
0.97169
0.93025
37.29
1
card_01_clean.png
clean
1
384
512
jpeg
80
20,352
0.8281
0.97888
0.95496
39.351
1.1
card_01_clean.png
clean
1
384
512
jpeg
85
24,170
0.9835
0.98286
0.96842
40.935
1.1
card_01_clean.png
clean
1
384
512
jpeg
90
30,750
1.2512
0.98726
0.97944
43.216
1.2
card_01_clean.png
clean
1
384
512
jpeg
95
44,004
1.7905
0.99243
0.99087
46.997
1.7
card_01_clean.png
clean
1
384
512
webp
50
9,164
0.3729
0.97009
0.90763
37.635
11.5
card_01_clean.png
clean
1
384
512
webp
60
9,980
0.4061
0.9739
0.9228
38.49
11.3
card_01_clean.png
clean
1
384
512
webp
70
11,326
0.4609
0.97649
0.9334
39.368
11.5
card_01_clean.png
clean
1
384
512
webp
80
13,852
0.5636
0.98268
0.96035
41.495
11.8
card_01_clean.png
clean
1
384
512
webp
85
16,730
0.6807
0.98546
0.97334
43.078
12.3
card_01_clean.png
clean
1
384
512
webp
90
21,166
0.8612
0.9891
0.98562
45.188
13
card_01_clean.png
clean
1
384
512
webp
95
32,672
1.3294
0.99329
0.99445
48.3
15.3
card_01_clean.png
clean
1
384
512
avif
40
5,195
0.2114
0.95704
0.79843
33.816
63.2
card_01_clean.png
clean
1
384
512
avif
50
7,559
0.3076
0.97393
0.90204
36.839
69.7
card_01_clean.png
clean
1
384
512
avif
60
10,482
0.4265
0.98222
0.94668
39.685
77.2
card_01_clean.png
clean
1
384
512
avif
70
13,813
0.5621
0.98668
0.97112
42.676
85
card_01_clean.png
clean
1
384
512
avif
80
17,961
0.7308
0.98952
0.98266
44.807
97.5
card_01_clean.png
clean
1
384
512
avif
90
27,167
1.1054
0.99377
0.99381
48.175
118
card_01_clean.png
clean
1
384
512
png
null
120,627
4.9083
1
1
99
119.3
card_01_clean.png
clean
1
384
512
webp_lossless
null
77,432
3.1507
1
1
99
86.7
card_02_clean.png
clean
2
768
1,024
jpeg
50
48,420
0.4926
0.94417
0.90145
33.339
2.7
card_02_clean.png
clean
2
768
1,024
jpeg
60
55,417
0.5637
0.94998
0.92136
34.441
3.1
card_02_clean.png
clean
2
768
1,024
jpeg
70
66,396
0.6754
0.95659
0.94
35.915
3.4
card_02_clean.png
clean
2
768
1,024
jpeg
80
84,997
0.8646
0.9646
0.96022
38.087
3.8
card_02_clean.png
clean
2
768
1,024
jpeg
85
100,408
1.0214
0.96973
0.97009
39.655
4.1
card_02_clean.png
clean
2
768
1,024
jpeg
90
127,168
1.2936
0.9767
0.98085
41.863
4.6
card_02_clean.png
clean
2
768
1,024
jpeg
95
184,699
1.8789
0.98791
0.99305
45.845
6.4
card_02_clean.png
clean
2
768
1,024
webp
50
34,054
0.3464
0.95921
0.94676
37.922
41
card_02_clean.png
clean
2
768
1,024
webp
60
37,052
0.3769
0.96186
0.95491
38.718
41.4
card_02_clean.png
clean
2
768
1,024
webp
70
40,586
0.4129
0.9645
0.96405
39.535
42.5
card_02_clean.png
clean
2
768
1,024
webp
80
51,952
0.5285
0.97156
0.9793
41.4
44.2
card_02_clean.png
clean
2
768
1,024
webp
85
63,710
0.6481
0.97823
0.98701
42.935
47.9
card_02_clean.png
clean
2
768
1,024
webp
90
88,738
0.9027
0.98774
0.99362
45.536
53
card_02_clean.png
clean
2
768
1,024
webp
95
126,024
1.282
0.99563
0.99732
49.596
59.5
card_02_clean.png
clean
2
768
1,024
avif
40
16,057
0.1633
0.9597
0.94451
38.741
232.2
card_02_clean.png
clean
2
768
1,024
avif
50
23,979
0.2439
0.9726
0.97931
41.935
267.7
card_02_clean.png
clean
2
768
1,024
avif
60
35,884
0.365
0.99053
0.99288
46.102
279.4
card_02_clean.png
clean
2
768
1,024
avif
70
42,714
0.4345
0.99483
0.99658
48.047
291.3
card_02_clean.png
clean
2
768
1,024
avif
80
49,786
0.5064
0.99696
0.99789
49.799
313.4
card_02_clean.png
clean
2
768
1,024
avif
90
61,047
0.621
0.99844
0.99906
51.853
353
card_02_clean.png
clean
2
768
1,024
png
null
166,466
1.6934
1
1
99
219.8
card_02_clean.png
clean
2
768
1,024
webp_lossless
null
106,126
1.0796
1
1
99
216.5
card_02_clean.png
clean
2
384
512
jpeg
50
12,267
0.4991
0.95952
0.87337
34.869
0.9
card_02_clean.png
clean
2
384
512
jpeg
60
13,910
0.566
0.96568
0.89866
35.87
1
card_02_clean.png
clean
2
384
512
jpeg
70
16,305
0.6635
0.97229
0.92579
37.245
1
card_02_clean.png
clean
2
384
512
jpeg
80
20,708
0.8426
0.97915
0.95313
39.258
1
card_02_clean.png
clean
2
384
512
jpeg
85
24,586
1.0004
0.98317
0.9658
40.824
1.1
card_02_clean.png
clean
2
384
512
jpeg
90
31,225
1.2705
0.98761
0.97785
43.107
1.2
card_02_clean.png
clean
2
384
512
jpeg
95
44,813
1.8234
0.99258
0.99018
46.949
1.4
card_02_clean.png
clean
2
384
512
webp
50
9,316
0.3791
0.97292
0.91641
37.516
11.1
card_02_clean.png
clean
2
384
512
webp
60
10,420
0.424
0.97652
0.93387
38.503
11.7
card_02_clean.png
clean
2
384
512
webp
70
11,524
0.4689
0.97897
0.94325
39.366
11.6
card_02_clean.png
clean
2
384
512
webp
80
14,100
0.5737
0.98375
0.96485
41.316
11.8
card_02_clean.png
clean
2
384
512
webp
85
16,800
0.6836
0.98678
0.97602
43.061
12.3
card_02_clean.png
clean
2
384
512
webp
90
21,278
0.8658
0.98933
0.98524
44.975
13.2
card_02_clean.png
clean
2
384
512
webp
95
33,008
1.3431
0.99343
0.99432
48.262
16.3
card_02_clean.png
clean
2
384
512
avif
40
5,255
0.2138
0.95609
0.82135
33.756
63.3
card_02_clean.png
clean
2
384
512
avif
50
7,642
0.311
0.97382
0.90388
36.723
74.3
card_02_clean.png
clean
2
384
512
avif
60
10,581
0.4305
0.98239
0.94946
39.536
79.5
card_02_clean.png
clean
2
384
512
avif
70
14,019
0.5704
0.98706
0.97368
42.684
89.9
card_02_clean.png
clean
2
384
512
avif
80
18,221
0.7414
0.9899
0.98447
44.939
99.3
card_02_clean.png
clean
2
384
512
avif
90
27,616
1.1237
0.99401
0.99479
48.244
124.1
card_02_clean.png
clean
2
384
512
png
null
118,380
4.8169
1
1
99
116.7
card_02_clean.png
clean
2
384
512
webp_lossless
null
76,936
3.1305
1
1
99
86.8
card_03_clean.png
clean
3
768
1,024
jpeg
50
49,966
0.5083
0.94152
0.88838
33.175
2.9
card_03_clean.png
clean
3
768
1,024
jpeg
60
57,239
0.5823
0.94811
0.91209
34.265
3.4
card_03_clean.png
clean
3
768
1,024
jpeg
70
68,694
0.6988
0.95532
0.93455
35.745
3.6
card_03_clean.png
clean
3
768
1,024
jpeg
80
88,118
0.8964
0.96365
0.95559
37.91
3.9
card_03_clean.png
clean
3
768
1,024
jpeg
85
103,824
1.0562
0.96902
0.96642
39.489
4.5
card_03_clean.png
clean
3
768
1,024
jpeg
90
131,689
1.3396
0.97614
0.97858
41.69
4.9
card_03_clean.png
clean
3
768
1,024
jpeg
95
191,189
1.9449
0.98768
0.992
45.652
5.6
card_03_clean.png
clean
3
768
1,024
webp
50
35,606
0.3622
0.95839
0.94352
37.792
42.5
card_03_clean.png
clean
3
768
1,024
webp
60
38,668
0.3934
0.96106
0.95216
38.566
44.3
card_03_clean.png
clean
3
768
1,024
webp
70
42,678
0.4341
0.96423
0.96224
39.331
43.1
card_03_clean.png
clean
3
768
1,024
webp
80
53,546
0.5447
0.97093
0.97799
41.155
47.4
card_03_clean.png
clean
3
768
1,024
webp
85
66,336
0.6748
0.97848
0.98577
42.767
48.8
End of preview. Expand in Data Studio

Malfoid AI Encode Ladder 2026-11-12: How Small Can a 3:4 Portrait Get in JPEG, WebP and AVIF Before the Hair Breaks? (1,320 Encodes, SSIM on the Hair)

Snapshot built November 12, 2026, around 18:00 CST (UTC+8), by the builder of malfoidai.com, an independent, unofficial studio for still Malfoid (Female Malfoy / Fem Draco) portraits. First-party measurements on synthetic images, not an independent benchmark. Dataset card v8.

Short answer: the new default config, encode_ladder, has 1,320 rows: each of the 30 synthetic test_cards at 2 widths (768 px, the 1K 3:4 frame, and 384 px for a blog column) × 22 encodes (JPEG q50–95, WebP q50–95, AVIF q40–90, lossless PNG and lossless WebP). Every row has the file size, bits per pixel, luma PSNR, whole-frame SSIM and SSIM over the hair box, because fine platinum strands are where compression shows first. It answers a question people ask before putting a portrait on a site or in a chat: what format and quality should I export, and how big will it be?

What the numbers say on these cards (all computed by encode_ladder.py, below). The target is median hair SSIM ≥ 0.98:

  • At 768 px: AVIF q60 ≈ 36 KB, WebP q85 ≈ 63 KB, JPEG q90 ≈ 126 KB. All three reach the same hair quality. AVIF is about 3.5× smaller than JPEG there, and lossless PNG is 172 KB.
  • At 384 px you need higher quality settings (JPEG q95, WebP q90, AVIF q80). Halving the width packs the strands closer together, so the same quality setting loses more of them. A small thumbnail exported at "q80 like the big one" looks worse than you'd expect.
  • AVIF's quality scale is steep. q40 → q60 at 768 px goes from 0.93 to 0.99 hair SSIM, so don't copy JPEG numbers into an AVIF setting.
  • AVIF is the slowest: median 279 ms per 768 px encode here, against 45 ms for WebP and 4 ms for JPEG. That doesn't matter for one export, but it does for a batch job on every upload.
  • Lossless WebP is 36% smaller than optimised PNG (111 vs 172 KB) for an identical picture. If you need lossless (for example before further editing), WebP lossless is the cheaper archive.

The older configs are unchanged and carried forward. I re-ran verify_facts.py against the live site today: 30 records, 11 pages, 0 missing or gone, 0 page-date changes.

Lowest quality reaching median hair SSIM ≥ 0.98 (verbatim output)

1320 rows from 30 cards. Per format: lowest quality whose MEDIAN ssim_hair >= 0.98, and median size there.

width 768px
  format         quality  median KB  median ssim  ssim_hair  worst hair
  jpeg                90      126.0       0.9765     0.9812      0.9757
  webp                85       63.4       0.9786     0.9865      0.9793
  avif                60       36.1       0.9906     0.9919      0.9754
  png                  -      172.1       1.0000     1.0000      1.0000
  webp_lossless        -      110.6       1.0000     1.0000      1.0000

width 384px
  format         quality  median KB  median ssim  ssim_hair  worst hair
  jpeg                95       44.0       0.9925     0.9906      0.9875
  webp                90       21.1       0.9894     0.9849      0.9799
  avif                80       18.0       0.9898     0.9845      0.9793
  png                  -      118.4       1.0000     1.0000      1.0000
  webp_lossless        -       76.5       1.0000     1.0000      1.0000

The whole ladder, medians over 30 cards

width 768px: median KB / median ssim_hair over 30 cards
  jpeg  q50 48KB/0.904  q60 55KB/0.923  q70 66KB/0.942  q80 84KB/0.961  q85 99KB/0.971  q90 126KB/0.981  q95 183KB/0.993
  webp  q50 34KB/0.947  q60 37KB/0.955  q70 41KB/0.965  q80 51KB/0.979  q85 63KB/0.987  q90 88KB/0.993  q95 125KB/0.997
  avif  q40 16KB/0.932  q50 24KB/0.972  q60 36KB/0.992  q70 43KB/0.996  q80 50KB/0.997  q90 61KB/0.999
  png           172KB (lossless)
  webp_lossless 111KB (lossless)
  median encode ms: jpeg 4, webp 45, avif 279, png 227, webp_lossless 217
width 384px: median KB / median ssim_hair over 30 cards
  jpeg  q50 12KB/0.882  q60 14KB/0.904  q70 16KB/0.930  q80 20KB/0.955  q85 24KB/0.966  q90 31KB/0.979  q95 44KB/0.991
  webp  q50 9KB/0.909  q60 10KB/0.923  q70 11KB/0.937  q80 14KB/0.961  q85 16KB/0.974  q90 21KB/0.985  q95 32KB/0.994
  avif  q40 5KB/0.832  q50 7KB/0.907  q60 10KB/0.951  q70 14KB/0.973  q80 18KB/0.984  q90 27KB/0.994
  png           118KB (lossless)
  webp_lossless 77KB (lossless)
  median encode ms: jpeg 1, webp 12, avif 86, png 121, webp_lossless 88

Fields (data/encode-ladder-2026-11-12.jsonl)

Field Type Meaning
file_name, variant, seed string, string, int The test card (see test_cards below)
width, height int Encoded size: 768 × 1024 (native) or 384 × 512 (Lanczos); square cards are 768 × 768 / 384 × 384
format string jpeg, webp, avif, png, webp_lossless
quality int or null Encoder quality (null for lossless)
bytes, bpp int, float File size, and bits per pixel
ssim float Gaussian SSIM (σ 1.5) on Rec.601 luma, whole frame, vs the uncompressed image at the same width
ssim_hair float Mean of the same SSIM map over the card's regions.hair box
psnr_y float Luma PSNR in dB (99 = identical)
encode_ms float Wall-clock encode time on the build machine; compare only within this file

Encoder settings: Pillow 13.0, JPEG optimize=True with Pillow's default chroma subsampling, WebP method=4, AVIF speed=6 (Pillow's bundled libavif), PNG optimize=True.

The script

#!/usr/bin/env python3
"""Size vs quality ladder for exporting a 3:4 portrait: JPEG, WebP, AVIF and
lossless PNG/WebP at two widths, scored with luma SSIM and PSNR.

    pip install pillow numpy          # Pillow >= 11.3 for AVIF
    python encode_ladder.py data/test-cards-2026-11-09 > data/encode-ladder-2026-11-12.jsonl
    python encode_ladder.py data/test-cards-2026-11-09 --summary

One row per card x width x format x quality. SSIM is the standard Gaussian
(sigma 1.5, K1 0.01, K2 0.03) on Rec.601 luma, computed here in NumPy so the
numbers don't depend on a particular SSIM package. `ssim_hair` is the same
SSIM averaged over the card's hair box (fine strands are where compression
shows first). Encode times are wall-clock on the machine that built the file
and are only comparable within one file.
"""
import io
import json
import os
import sys
import time
import numpy as np
from PIL import Image

LADDER = [("jpeg", q) for q in (50, 60, 70, 80, 85, 90, 95)] + \
         [("webp", q) for q in (50, 60, 70, 80, 85, 90, 95)] + \
         [("avif", q) for q in (40, 50, 60, 70, 80, 90)] + \
         [("png", None), ("webp_lossless", None)]
WIDTHS = (768, 384)


def encode(img, fmt, q):
    b = io.BytesIO()
    if fmt == "jpeg":
        img.save(b, "JPEG", quality=q, optimize=True)
    elif fmt == "webp":
        img.save(b, "WEBP", quality=q, method=4)
    elif fmt == "avif":
        img.save(b, "AVIF", quality=q, speed=6)
    elif fmt == "png":
        img.save(b, "PNG", optimize=True)
    elif fmt == "webp_lossless":
        img.save(b, "WEBP", lossless=True, method=4)
    return b.getvalue()


def luma(a):
    return a[..., 0] * 0.299 + a[..., 1] * 0.587 + a[..., 2] * 0.114


def _blur(x, sigma=1.5):
    r = int(np.ceil(3.5 * sigma))
    k = np.exp(-0.5 * (np.arange(-r, r + 1) / sigma) ** 2)
    k /= k.sum()
    p = np.pad(x, r, mode="reflect")
    p = np.apply_along_axis(lambda v: np.convolve(v, k, mode="valid"), 0, p)
    return np.apply_along_axis(lambda v: np.convolve(v, k, mode="valid"), 1, p)


def ssim_map(x, y):
    C1, C2 = (0.01 * 255) ** 2, (0.03 * 255) ** 2
    mx, my = _blur(x), _blur(y)
    sxx = _blur(x * x) - mx * mx
    syy = _blur(y * y) - my * my
    sxy = _blur(x * y) - mx * my
    return ((2 * mx * my + C1) * (2 * sxy + C2)) / ((mx * mx + my * my + C1) * (sxx + syy + C2))


def psnr(x, y):
    mse = np.mean((x - y) ** 2)
    return 99.0 if mse == 0 else float(10 * np.log10(255 ** 2 / mse))


def rows_for(path, meta):
    src = Image.open(path).convert("RGB")
    for W in WIDTHS:
        img = src if src.size[0] == W else src.resize((W, round(W * src.size[1] / src.size[0])), Image.Resampling.LANCZOS)
        ref = luma(np.asarray(img, dtype=np.float64))
        H = ref.shape[0]
        x0, y0, x1, y1 = meta["regions"]["hair"]
        hair = (slice(int(y0 * H), int(y1 * H)), slice(int(x0 * W), int(x1 * W)))
        for fmt, q in LADDER:
            t = time.perf_counter()
            data = encode(img, fmt, q)
            ms = (time.perf_counter() - t) * 1000
            dec = luma(np.asarray(Image.open(io.BytesIO(data)).convert("RGB"), dtype=np.float64))
            m = ssim_map(ref, dec)
            yield {"file_name": meta["file_name"], "variant": meta["variant"], "seed": meta["seed"],
                   "width": img.size[0], "height": img.size[1], "format": fmt, "quality": q,
                   "bytes": len(data), "bpp": round(len(data) * 8 / (img.size[0] * img.size[1]), 4),
                   "ssim": round(float(m.mean()), 5), "ssim_hair": round(float(m[hair].mean()), 5),
                   "psnr_y": round(psnr(ref, dec), 3), "encode_ms": round(ms, 1)}


def summary(rows, target=0.98):
    out = [f"{len(rows)} rows from {len({r['file_name'] for r in rows})} cards. "
           f"Per format: lowest quality whose MEDIAN ssim_hair >= {target}, and median size there.", ""]
    for W in WIDTHS:
        out.append(f"width {W}px")
        out.append(f"  {'format':<14}{'quality':>8}{'median KB':>11}{'median ssim':>13}{'ssim_hair':>11}{'worst hair':>12}")
        for fmt in ("jpeg", "webp", "avif", "png", "webp_lossless"):
            qs = sorted({r["quality"] for r in rows if r["format"] == fmt and r["width"] == W}, key=lambda v: (v is None, v))
            pick = None
            for q in qs:
                sel = [r for r in rows if r["format"] == fmt and r["width"] == W and r["quality"] == q]
                if np.median([r["ssim_hair"] for r in sel]) >= target:
                    pick = (q, sel)
                    break
            if not pick:
                out.append(f"  {fmt:<14}{'none':>8}")
                continue
            q, sel = pick
            out.append(f"  {fmt:<14}{str(q if q is not None else '-'):>8}"
                       f"{np.median([r['bytes'] for r in sel]) / 1024:>11.1f}"
                       f"{np.median([r['ssim'] for r in sel]):>13.4f}"
                       f"{np.median([r['ssim_hair'] for r in sel]):>11.4f}"
                       f"{min(r['ssim_hair'] for r in sel):>12.4f}")
        out.append("")
    return "\n".join(out)


def main():
    d = sys.argv[1]
    if "--summary" in sys.argv:
        f = sys.argv[sys.argv.index("--summary") + 1] if len(sys.argv) > sys.argv.index("--summary") + 1 else None
        rows = [json.loads(l) for l in open(f)] if f else \
            [r for m in map(json.loads, open(os.path.join(d, "metadata.jsonl"))) for r in rows_for(os.path.join(d, m["file_name"]), m)]
        print(summary(rows))
        return
    for line in open(os.path.join(d, "metadata.jsonl")):
        m = json.loads(line)
        for r in rows_for(os.path.join(d, m["file_name"]), m):
            print(json.dumps(r))


if __name__ == "__main__":
    main()
pip install pillow numpy datasets
python encode_ladder.py data/test-cards-2026-11-09 > data/encode-ladder-2026-11-12.jsonl   # ~4 min
python encode_ladder.py data/test-cards-2026-11-09 --summary data/encode-ladder-2026-11-12.jsonl
from datasets import load_dataset
rows = load_dataset("conan123/malfoidai-guides", "encode_ladder", split="train")
small = rows.filter(lambda r: r["width"] == 768 and r["ssim_hair"] >= 0.98)
print(min(small, key=lambda r: r["bytes"]))

How to use it on a real portrait

Run encode_ladder.py on a folder with your own picture and a one-line metadata.jsonl ({"file_name": "mine.png", "variant": "mine", "seed": 0, "regions": {"hair": [0.24, 0.3, 0.32, 0.55]}}; the hair box is fractions of the frame). A real rendered portrait has more texture than these cards, so expect bigger files at every setting. The ordering (AVIF < WebP < JPEG at equal hair SSIM, higher quality needed for smaller widths) is the part worth carrying over, not the KB numbers.

Previous config: caption_contrast (2026-11-11)

Short answer: the config caption_contrast, has 2,160 rows: each of the 30 synthetic test_cards x 9 caption placements (a 3x3 grid) x 4 text colours (white, black, silver #C0C0C0, tie green #1A5C34) x 2 treatments (no scrim, 50% black scrim). Every row holds the WCAG 2.x contrast ratio between the text colour and the pixels behind the caption box: the median and the 10th percentile (the darkest or brightest tenth, where letters actually get lost). It answers a question people ask before posting a portrait with a caption: where can the words go, and in what colour?

What the numbers say on these cards (all values computed by caption_contrast.py, below):

  • Top corners and top-centre: white or silver text passes AA (p10 >= 4.5) on 30 of 30 cards with no scrim (median p10 for white: 13.0-14.9). The dark corridor above the head is the safest caption area.
  • Bottom-left / bottom-right: white or silver passes on 28 of 30 (the 2 failures are the square cards, where the robe edge moves).
  • Middle-left / middle-right (beside the face): no colour passes without a scrim (white p10 1.35). The cell straddles the platinum hair and the dark background, so any single colour vanishes on one half. A 50% black scrim fixes it for white (p10 5.03, 30 of 30).
  • Bottom-centre (over the shirt and tie): nothing reliably passes, even white with a scrim (2 of 30). Don't caption over the tie.
  • Tie green as a text colour fails AA in every cell (median p10 1.0-2.8). The "house colour" is a fill colour, not a caption colour, on a dark portrait.

Share of cards passing WCAG AA (p10 >= 4.5) by placement (verbatim output)

2160 rows from 30 cards. Share of cards where p10 contrast >= 4.5 (WCAG AA, normal text):

scrim=none
cell              white   black  silver   green
top-left           100%      0%    100%      0%
top-centre         100%      0%    100%      0%
top-right          100%      0%    100%      0%
middle-left          0%      0%      0%      0%
middle-centre        0%    100%      0%      0%
middle-right         0%      0%      0%      0%
bottom-left         93%      0%     93%      0%
bottom-centre        0%      7%      0%      0%
bottom-right        93%      0%     93%      0%

scrim=black50
cell              white   black  silver   green
top-left           100%      0%    100%      0%
top-centre         100%      0%    100%      0%
top-right          100%      0%    100%      0%
middle-left        100%      0%      0%      0%
middle-centre      100%      0%      0%      0%
middle-right       100%      0%      0%      0%
bottom-left        100%      0%     93%      0%
bottom-centre        7%      0%      0%      0%
bottom-right       100%      0%     93%      0%

Fields (data/caption-contrast-2026-11-11.jsonl)

Field Type Meaning
file_name, variant, seed string, string, int The test card (see test_cards below)
width, height int Card size in px (768 x 1024, or 1024 x 1024 for square)
row, col string top / middle / bottom and left / centre / right
box list Caption box [x, y, w, h] in px: w = W/3, h = H/8; top edge at 3%, 43.75% and 84.5% of H
scrim string none, or black50 (background darkened by 50% before measuring)
text_colour string white, black, silver (192,192,192), green (26,92,52)
contrast_median, contrast_p10 float WCAG 2.x contrast ratio, text vs each background pixel: median and 10th percentile
background_luma_std float Std-dev of Rec.601 luma in the box (how busy it is), scrim none
aa_large_p10, aa_normal_p10 bool p10 >= 3.0 (AA large text) and p10 >= 4.5 (AA normal text)

The script

#!/usr/bin/env python3
"""Caption readability on 3:4 portraits: WCAG contrast of caption colours at
nine placements, with and without a 50% black scrim.

    pip install pillow numpy
    python caption_contrast.py data/test-cards-2026-11-09 > data/caption-contrast-2026-11-11.jsonl
    python caption_contrast.py data/test-cards-2026-11-09 --summary

For every card, every cell of a 3x3 grid (each cell 1/3 of the width and
1/8 of the height, rows anchored at the top, middle and bottom), every text
colour and both scrim settings, it computes the WCAG 2.x contrast ratio
between the text colour and each background pixel, then reports the median
and the 10th percentile (the worst-lit tenth of the cell, where letters
would actually get lost).
"""
import json, os, sys
import numpy as np
from PIL import Image

COLOURS = {"white": (255, 255, 255), "black": (0, 0, 0),
           "silver": (192, 192, 192), "green": (26, 92, 52)}
ROWS = {"top": 0.03, "middle": 0.4375, "bottom": 0.845}   # cell top as a fraction of H
COLS = {"left": 0, "centre": 1, "right": 2}
SCRIMS = {"none": 0.0, "black50": 0.5}

def rel_lum(rgb):
    c = np.asarray(rgb, dtype=np.float64) / 255
    c = np.where(c <= 0.04045, c / 12.92, ((c + 0.055) / 1.055) ** 2.4)
    return c @ np.array([0.2126, 0.7152, 0.0722])

def contrast(l1, l2):
    hi, lo = np.maximum(l1, l2), np.minimum(l1, l2)
    return (hi + 0.05) / (lo + 0.05)

def rows_for(path, meta):
    a = np.asarray(Image.open(path).convert("RGB"), dtype=np.float64)
    H, W, _ = a.shape
    ch, cw = H // 8, W // 3
    for rname, ry in ROWS.items():
        for cname, ci in COLS.items():
            y0, x0 = int(ry * H), ci * cw
            cell = a[y0:y0 + ch, x0:x0 + cw].reshape(-1, 3)
            luma = cell @ np.array([0.299, 0.587, 0.114])
            for sname, k in SCRIMS.items():
                bg = rel_lum(cell * (1 - k))           # scrim = darken by k
                for col, rgb in COLOURS.items():
                    cr = contrast(rel_lum(rgb), bg)
                    p10, med = np.percentile(cr, 10), np.median(cr)
                    yield dict(file_name=meta["file_name"], variant=meta["variant"], seed=meta["seed"],
                               width=W, height=H, row=rname, col=cname,
                               box=[x0, y0, cw, ch], scrim=sname, text_colour=col,
                               contrast_median=round(float(med), 2), contrast_p10=round(float(p10), 2),
                               background_luma_std=round(float(luma.std()), 1),
                               aa_large_p10=bool(p10 >= 3.0), aa_normal_p10=bool(p10 >= 4.5))

def main():
    d = sys.argv[1] if len(sys.argv) > 1 else "data/test-cards-2026-11-09"
    meta = [json.loads(l) for l in open(os.path.join(d, "metadata.jsonl"))]
    rows = [r for m in meta for r in rows_for(os.path.join(d, m["file_name"]), m)]
    if "--summary" not in sys.argv:
        for r in rows:
            print(json.dumps(r))
        return
    n_cards = len(meta)
    print(f"{len(rows)} rows from {n_cards} cards. Share of cards where p10 contrast >= 4.5 (WCAG AA, normal text):")
    for sname in SCRIMS:
        print(f"\nscrim={sname}")
        print(f"{'cell':<15}" + "".join(f"{c:>8}" for c in COLOURS))
        for rname in ROWS:
            for cname in COLS:
                sel = [r for r in rows if r["row"] == rname and r["col"] == cname and r["scrim"] == sname]
                line = f"{rname + '-' + cname:<15}"
                for c in COLOURS:
                    s = [r for r in sel if r["text_colour"] == c]
                    line += f"{sum(r['aa_normal_p10'] for r in s) / len(s):>8.0%}"
                print(line)

if __name__ == "__main__":
    main()
pip install pillow numpy datasets
python caption_contrast.py data/test-cards-2026-11-09 > data/caption-contrast-2026-11-11.jsonl
python caption_contrast.py data/test-cards-2026-11-09 --summary
from datasets import load_dataset
rows = load_dataset("conan123/malfoidai-guides", "caption_contrast", split="train")
safe = rows.filter(lambda r: r["scrim"] == "none" and r["aa_normal_p10"])
print(len(safe), "placements pass AA without a scrim")

How to use it on a real portrait

Run caption_contrast.py on a folder with your own picture and a one-line metadata.jsonl ({"file_name": "mine.png", "variant": "mine", "seed": 0}). The synthetic cards have fixed framing; a real portrait from a photo will move the hair edge and the candle glow, so the middle cells in particular will vary.

Previous config: test_cards (2026-11-09)

What's in test_cards

Variant Cards What was done Expected gate verdict
clean 8 (seeds 1–8) Nothing. These are the golden batch. PASS
text 12 (seeds 9–20) One line of 4–9 nonsense capitals (14–34 px, slight rotation) pasted on the wall or the robe PASS (lettering isn't a drift property)
red_tie 3 Tie recoloured red (off-palette) FAIL
warm_hair 3 Platinum pushed toward yellow FAIL
square 2 1024 × 1024 frame instead of 768 × 1024 FAIL
soft 2 2x down, then bilinear back up (a soft upscaler) DRIFT or FAIL

All cards have thin hair-strand texture, so sharpness metrics behave like they would on a rendered portrait rather than on flat vector shapes.

Fields (data/test-cards-2026-11-09/metadata.jsonl)

Field Type Meaning
file_name string PNG in the same folder (the image column when loaded with datasets)
card int 1–30
variant string clean, text, red_tie, warm_hair, square, soft
seed int Seed for make_test_portrait.py (face shape and skin tone vary with it)
texture bool Always true in this snapshot
width, height int Pixel size
has_text bool True for the 12 lettering cards
text object or null text, font_px, box [x, y, w, h] in px, colour RGB, contrast (abs. luma difference between letters and the median of the box background, 0–255)
regions object Fractions of the frame for hair, tie, background [x0, y0, x1, y1], as used by the gate
face_box_px list Face ellipse bounding box [x, y, w, h], replayed from the drawing RNG
expected_gate string PASS, FAIL or DRIFT_OR_FAIL

Lettering contrast in this set: 10 cards between 140 and 215 (clearly visible) and 2 cards at 6 (near-black on near-black, hard to see even when enlarged).

Baseline results (verbatim)

== stray text (clean + text cards)
  false alarm card_02_clean.png
  missed card_11_text.png: 'GWFWCDTGB' 25 px, contrast 6
  missed card_15_text.png: 'TARCAD' 29 px, contrast 6
  missed card_19_text.png: 'WASOV' 30 px, contrast 143
  text found 9/12; clean cards flagged 1/8
== preset gate (each card alone vs the 8 clean cards)
  card_09_text.png           expected PASS          got PASS  (-)
  ...
  card_20_text.png           expected PASS          got PASS  (-)
  card_21_red_tie.png        expected FAIL          got FAIL  (tie_hue,tie_chroma)
  card_22_red_tie.png        expected FAIL          got FAIL  (tie_hue,tie_chroma)
  card_23_red_tie.png        expected FAIL          got FAIL  (tie_hue,tie_chroma)
  card_24_warm_hair.png      expected FAIL          got FAIL  (hair_b)
  card_25_warm_hair.png      expected FAIL          got FAIL  (hair_b)
  card_26_warm_hair.png      expected FAIL          got FAIL  (hair_b)
  card_27_square.png         expected FAIL          got FAIL  (aspect,tie_hue,tie_chroma)
  card_28_square.png         expected FAIL          got FAIL  (aspect,tie_hue,tie_chroma)
  card_29_soft.png           expected DRIFT_OR_FAIL got DRIFT (edge_step)
  card_30_soft.png           expected DRIFT_OR_FAIL got DRIFT (edge_step)
  gate matches expectation on 22/22 cards

(All 12 text cards PASS the gate; the elided lines are identical in form.)

What the baselines get wrong, and why that's useful

  • Two contrast-6 misses are near-invisible lettering. A detector that finds them is doing better than a casual human check, which matters if someone brightens or prints the picture.
  • The contrast-143 miss (WASOV) is visible lettering the baseline should catch. That's the interesting failure for anyone building a better detector.
  • The card_02 false alarm comes from hair-strand texture: some strand fragments pass the letter-size and even-stroke tests and line up. Real portraits will produce more of these (book spines, window frames).
  • square cards fail on tie colour too, because the tie box is defined in frame fractions and lands on the shirt in a square frame. Correct verdict, noisy explanation. A gate should be read top-down: aspect first.
  • The gate is easy on this set. Each defect is strong and single. Mild, mixed drifts are harder; build them with the make_cards.py helpers (recolour_tie, warm_hair) at smaller strengths.

Files

Path What
data/encode-ladder-2026-11-12.jsonl 1,320 encode rows (new, default config)
encode_ladder.py Builds the rows from the test cards and prints the summary
data/caption-contrast-2026-11-11.jsonl 2,160 caption-placement rows (2026-11-11)
caption_contrast.py Builds the rows from the test cards and prints the summary
data/test-cards-2026-11-09/*.png + metadata.jsonl The 30 cards and labels (about 5 MB)
make_cards.py Rebuilds the cards exactly (fixed seeds)
make_test_portrait.py The shape-only drawing used for every card
stray_text.py Baseline 1: letter-like marks without OCR (OpenCV)
preset_regress.py + spec.json Baseline 2: batch drift gate (Pillow + NumPy)
eval_cards.py Runs both baselines on the cards
data/routes-2026-11-05.jsonl, data/pages-2026-11-05.jsonl, make_routes.py, build_corpus.py, route_eval.py Question routing set and BM25 baseline (2026-11-05)
data/facts-2026-11-04.jsonl, data/drift-2026-11-04.jsonl, verify_facts.py Dated facts with quotes and drift log; re-verified 2026-11-12 (30 of 30 OK)
data/review-rubric-2026-11-03.jsonl, data/answer-checks-2026-11-02.jsonl, data/records-2026-10-31.jsonl Unchanged

The evaluation script

#!/usr/bin/env python3
"""Run the two baselines on test_cards and print what they get right.

1. stray_text.py on the 20 clean + text cards: is there letter-like text?
2. preset_regress.py: golden = the 8 clean cards; every other card is
   checked alone (a batch of one) against it.

    pip install opencv-python-headless pillow numpy
    python eval_cards.py data/test-cards-2026-11-09
"""
import json, os, sys
import cv2
import preset_regress as pr
from stray_text import detect

d = sys.argv[1] if len(sys.argv) > 1 else "data/test-cards-2026-11-09"
rows = [json.loads(l) for l in open(os.path.join(d, "metadata.jsonl"))]
spec = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "spec.json")))
P = lambda r: os.path.join(d, r["file_name"])

print("== stray text (clean + text cards)")
tp = fn = fp = tn = 0
for r in rows:
    if r["variant"] not in ("clean", "text"):
        continue
    found = detect(cv2.imread(P(r)))
    if r["has_text"]:
        x, y, w, h = r["text"]["box"]
        hit = any(not (b["box"][0] > x + w or b["box"][0] + b["box"][2] < x or
                       b["box"][1] > y + h or b["box"][1] + b["box"][3] < y) for b in found)
        tp += hit; fn += not hit
        if not hit:
            print(f"  missed {r['file_name']}: '{r['text']['text']}' {r['text']['font_px']} px, contrast {r['text']['contrast']}")
    else:
        fp += bool(found); tn += not found
        if found:
            print(f"  false alarm {r['file_name']}")
print(f"  text found {tp}/{tp + fn}; clean cards flagged {fp}/{fp + tn}")

print("== preset gate (each card alone vs the 8 clean cards)")
clean = [P(r) for r in rows if r["variant"] == "clean"]
golden = pr.batch(clean, spec)
ok = 0
checked = [r for r in rows if r["variant"] != "clean"]
for r in checked:
    worst, rep = pr.check(spec, golden, pr.batch([P(r)], spec))
    got = ["PASS", "DRIFT", "FAIL"][worst]
    exp = r["expected_gate"]
    good = got == exp or (exp == "DRIFT_OR_FAIL" and got != "PASS")
    ok += good
    flagged = ",".join(k for k, *_, res in rep if res != "PASS") or "-"
    print(f"  {r['file_name']:<26} expected {exp:<13} got {got:<5} ({flagged}){'' if good else '  <-- mismatch'}")
print(f"  gate matches expectation on {ok}/{len(checked)} cards")

Usage

from datasets import load_dataset
cards = load_dataset("conan123/malfoidai-guides", "test_cards", split="test")
print(cards[0]["variant"], cards[0]["image"].size)
pip install opencv-python-headless pillow numpy
python make_cards.py data/test-cards-2026-11-09   # rebuild (identical files)
python eval_cards.py data/test-cards-2026-11-09   # run both baselines
python verify_facts.py data/facts-2026-11-04.jsonl

To score your own text detector: for each card with has_text, a hit is any predicted box that overlaps text.box; for clean cards, any prediction is a false alarm. Report results by contrast band, since near-invisible lettering is a different problem from visible lettering.

Price facts in this snapshot

From the pricing page and pricing.md, re-read with curl on 2026-11-12 around 18:00 CST (UTC+8) (unchanged since the page's 2026-10-31 update):

  • One portrait: $4.99 from a photo or without one, 2 credits, no account needed. One still 3:4 picture at 1K. No watermark is added.
  • Packs (sign-in required, one-time, no renewal; the HTML page says "Credits never expire"): 30 credits $13.99, 100 credits $35.99, 200 credits $59.99.

Known caveats

  • Encode ladder: SSIM is luma only. Chroma loss (JPEG and WebP subsample colour) isn't in ssim/ssim_hair. The green tie can bleed slightly before the hair SSIM moves. Look at the tie at your chosen setting.
  • Encode ladder: synthetic cards compress unrealistically well. Flat shapes plus strand texture are kinder than a rendered portrait. Use the ranking, not the byte counts.
  • Encoder versions matter. AVIF and WebP results shift between libavif/libwebp releases and speed settings. This file is one build (Pillow 13.0).
  • Caption cells are fixed boxes (1/3 width x 1/8 height). A real caption is letter-shaped, so the p10 over the whole box is a conservative proxy for the pixels behind the letters, not a rendering test.
  • Contrast is computed per pixel against a flat text colour, without anti-aliasing, outlines or shadows. An outline or drop shadow changes the answer; a scrim is the only treatment measured here.
  • Synthetic is not real. Flat shapes plus strand texture are far easier than a rendered portrait. Numbers here are a smoke test for tooling, not a measure of how often real portraits contain lettering or drift.
  • Region boxes assume the fixed framing of these cards. On real portraits, recompute them from your own golden batch.
  • The labels are mine, generated by the same scripts that draw the cards. They're exact for what was drawn, but "expected gate verdict" reflects my tolerances in spec.json.
  • Small: 30 cards. Rebuild more with make_cards.py by extending PLAN.

License and attribution

CC BY 4.0 for data and card text; scripts MIT. Malfoid is unofficial fan art. malfoidai.com is independent and not affiliated with any book, film, studio or author. See the site's FAQ, guides and llms.txt.

Downloads last month
175