Integrate resize+levels finishing into the review UI's accept flow

Accept now writes two files: OUTDIR/{cid}.png stays the untouched
full-resolution archival crop exactly as before, and a new
OUTDIR/finished/{cid}.jpg holds the resized (long-edge default 800) and
gamma/black-point-leveled derivative, saved at quality 60. Gamma/black
point/pre-blur are per-cover overridable in a new "Finish" panel (same
nudge-button + live-preview pattern as "Crop edges"), defaulting to the
global settings (gamma 1.2, long edge 800, JPEG quality 60) configurable
in Setup. cdcrop_resize.resize_image() was split out from resize_one() so
the UI can call it in-memory without file I/O, same as cdcrop_levels'
apply_levels() already allowed.
This commit is contained in:
2026-11-11 23:38:07 -06:00
parent ab9aa05ac2
commit dbe6c44b68
2 changed files with 126 additions and 32 deletions
+26 -15
View File
@@ -36,28 +36,39 @@ from PIL import Image, ImageFilter
RESIZE_GAP = 3.0 # >=3.0: Pillow's box-reduce pre-pass is indistinguishable from a fair resample
def resize_image(im, long_edge, pre_blur=0.0):
"""Core resize, usable on an in-memory image (no file I/O). Returns (image, was_resized)."""
w, h = im.size
scale = long_edge / max(w, h)
if scale >= 1.0:
return im, False
new_w, new_h = round(w * scale), round(h * scale)
if pre_blur > 0:
im = im.filter(ImageFilter.GaussianBlur(pre_blur))
im = im.resize((new_w, new_h), resample=Image.LANCZOS, reducing_gap=RESIZE_GAP)
return im, True
def sharpen_image(im, radius, percent, threshold):
return im.filter(ImageFilter.UnsharpMask(radius=radius, percent=percent, threshold=threshold))
def resize_one(path, outdir, long_edge, pre_blur, sharpen, sharpen_radius, sharpen_percent, sharpen_threshold):
im = Image.open(path)
mode = im.mode
w, h = im.size
scale = long_edge / max(w, h)
if scale >= 1.0:
print(f" {os.path.basename(path)} {w}x{h} already <= {long_edge}px, copied as-is")
new_w, new_h = w, h
else:
new_w, new_h = round(w * scale), round(h * scale)
if pre_blur > 0:
im = im.filter(ImageFilter.GaussianBlur(pre_blur))
im = im.resize((new_w, new_h), resample=Image.LANCZOS, reducing_gap=RESIZE_GAP)
print(f" {os.path.basename(path)} {w}x{h} -> {new_w}x{new_h}"
out, resized = resize_image(im, long_edge, pre_blur)
if resized:
print(f" {os.path.basename(path)} {w}x{h} -> {out.size[0]}x{out.size[1]}"
+ (f" (pre-blur {pre_blur:g})" if pre_blur > 0 else ""))
else:
print(f" {os.path.basename(path)} {w}x{h} already <= {long_edge}px, copied as-is")
if sharpen:
im = im.filter(ImageFilter.UnsharpMask(radius=sharpen_radius, percent=sharpen_percent,
threshold=sharpen_threshold))
if im.mode != mode:
im = im.convert(mode)
out = sharpen_image(out, sharpen_radius, sharpen_percent, sharpen_threshold)
if out.mode != mode:
out = out.convert(mode)
out_path = os.path.join(outdir, os.path.basename(path))
im.save(out_path, format="PNG")
out.save(out_path, format="PNG")
def main():