Menu

1 / 2

Recoloring a Product Photo with an SVG Filter – and Where It Breaks

DEV Community: nextjs·Iurii Rogulia·1 day ago
#Qv1LwqkE
#devtonextjs#devto#dev#tint#master
Reading 0:00
15s threshold

Short answer: yes, one SVG filter can recolor a transparent-background product photo to any color. A feColorMatrix that desaturates the image, followed by a three-stop feComponentTransfer table, is about twenty lines. It works. But the result depends on the tonal range of the photo you feed it, and on the masters I tested that dependency pushed the colors darker or lighter than requested.

I found this while building a color preview for pi-pi.ee, an online shop I built. The shop stocks black, grey and white products; other colors are made to order, and a buyer has to imagine them. I wanted a live preview. I built the first version with an SVG filter and replaced it the next day. I measured both versions later, for this article, so you can decide whether the simple one is enough for your photos.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.