The four-step recipe that turns a photo into a pencil sketch
The pencil-sketch effect in photo editors is not a drawing program. It is four plain image steps that happen to leave lines where a person would draw them. First the photo is made grey. Then a copy is inverted, so light becomes dark. Then that negative is blurred. Last, the grey photo and the blurred negative are combined with a blend mode called colour dodge.
Colour dodge divides one picture by the inverse of the other: the result is grey times 255, divided by 255 minus the blurred negative. In a flat area the blurred negative of a grey of 150 is still 105, so the sum is 150 times 255, divided by 150, which is 255: white paper. Every flat area cancels out to white this way, whatever its shade. At an edge the blur has mixed in the neighbours. Take a dark pixel of 60 next to a bright area: its blurred negative is lower than 195, say 150, so the result is 60 times 255 divided by 105, which is 146. That pixel turns grey, and a line of such pixels is a pencil stroke.
The blur decides how wide the strokes are. Pencil uses a radius of 0.6% of the long side, which is 24 pixels on a 4,000 pixel photo and about 5 on the 800 pixel preview, so the preview and the download have strokes of the same width relative to the picture. Soft shading uses 1.5%, which spreads the strokes into broad soft shading. Bold lines keeps the Pencil radius and darkens the result with a power curve: a stroke of 146 becomes about 63, while white paper stays white.
The recipe suits photos with clear shapes and good light: faces, buildings, pets, and objects against a plain background. It also suits illustrations, where it brings out every outline. It is weaker on dim or low-contrast photos, which have few strong edges and come out pale, and on busy textures such as gravel or foliage, which turn into a scribble of fine lines.
The limits: the result is grey, and it is an effect, not a real drawing. It does not simplify shapes or choose which lines matter the way an artist would. The download keeps JPEG, PNG and WebP, and anything else comes out as PNG. The largest image it takes is 24 megapixels, or 10,000 pixels on a side.