diff --git a/src/MessageHandler/RenderImageMessageHandler.php b/src/MessageHandler/RenderImageMessageHandler.php index 723123e..516a50d 100644 --- a/src/MessageHandler/RenderImageMessageHandler.php +++ b/src/MessageHandler/RenderImageMessageHandler.php @@ -107,12 +107,14 @@ final class RenderImageMessageHandler // Per-pixel adjustments run on the PHOTO before the white canvas is // composited under it — otherwise the bars dominate the histogram and - // the contrast stretch over-clips the photo content to white. + // would skew any auto-leveling toward white. - // Auto-levels: stretch the tonal range, clipping 1% at each end. - // Fixes underexposed/dark photos so the full palette range is used. - $photoPixels = $imagick->getImageWidth() * $imagick->getImageHeight(); - $imagick->contrastStretchImage((int) ($photoPixels * 0.01), (int) ($photoPixels * 0.01)); + // Auto-levels via normalizeImage (default 2%/2% clip). Empirically + // contrastStretchImage's args are quantum-range intensity thresholds, + // not pixel counts, and even small ints (>= ~1) collapse low-tonal- + // range photos to pure white. normalizeImage uses the image's actual + // histogram percentiles and produces gentle, correct stretching. + $imagick->normalizeImage(); // Boost saturation 130%. Dark desaturated photos otherwise map almost // entirely to BLACK with scattered noise dots from error diffusion.