Pencil sketch — soft graphite via colour-dodge
`img.pencilSketch(strength)` runs the classic Photoshop / GIMP colour-dodge sketch: convert to greyscale, invert, blur, then divide the original grey by `1 - blurred_inverted`. The division amplifies subtle dark micro-detail at edges so they read as soft pencil strokes; flat regions stay near white. No edge-detection harshness — much closer to a real graphite drawing than naive Sobel sketches. `STRENGTH` is the blur sigma. 5-10 = fine hatching, 15-30 = broader graphite shading (default 20), 40+ = washed-out. A small brightness/contrast nudge afterwards keeps the result from going too pale.
INPUT
Pencil sketch
JavaScript
// Pencil-sketch effect — colour-dodge classic
// demo_pencil_sketch.js
//!INPUT: INPUT
//!OUTPUT: OUTPUT
//!PARAM: STRENGTH:number=20,min=2,max=60
//!PARAM: BRIGHTNESS_TOUCHUP:number=1.05,min=0.5,max=1.5
//!PARAM: CONTRAST_TOUCHUP:number=1.10,min=0.5,max=2.0
// `img.pencilSketch(strength)` is the classic Photoshop / GIMP
// "colour-dodge" trick: convert to greyscale, invert, blur,
// divide the original grey by `1 - blurred_inverted`. The
// division amplifies subtle dark micro-detail around edges so
// they read as soft pencil strokes; flat regions stay near
// white. No edge-detection harshness, much closer to a real
// graphite drawing than naive Sobel-style sketches.
//
// `STRENGTH` is the Gaussian sigma applied to the inverted
// copy:
// - 5–10 → tight, fine pencil hatching feel
// - 15–30 → broader graphite shading (default 20)
// - 40+ → washed-out, almost watercolour
//
// A small brightness/contrast nudge after the sketch keeps the
// result from going too washed-out — pencil drawings have more
// punchy mid-tones than a naive colour-dodge would give. Set
// either to 1.0 to disable.
const img = Engine.loadImage(INPUT);
img.pencilSketch(STRENGTH);
if (CONTRAST_TOUCHUP !== 1.0) { img.contrast(CONTRAST_TOUCHUP); }
if (BRIGHTNESS_TOUCHUP !== 1.0) { img.brightness(BRIGHTNESS_TOUCHUP); }
img.save(OUTPUT);
img.free();
// © 2026 Michael Lechner · mlc OpticScript · https://mlcgo.eu · Elastic License 2.0