Duotone
双色调
The image maps dark tones to one color and light tones to a second color.
Where to use it
Unify photos under a brand palette or give editorial imagery a poster-like look. Use the same shadow and highlight colors across a series, then check that you can still recognize the subject of each photo.
Practical example
A neighborhood newspaper gives three portraits in one history series indigo shadows and pale ochre highlights. The portraits read as a set and keep distinct faces even though the original photos were taken under different lighting.
AI prompt
Give [target image] a Duotone treatment. Map normalized luminance between the two brand colors, then adjust the tone curve to preserve important detail. Apply the color transform to the image layer and keep text on an independent accessible layer.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Duotone</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.visual-specimen {
width: min(100%, 290px);
height: 124px;
display: grid;
place-items: center;
position: relative;
isolation: isolate;
}
.duotone-pair { display: flex; justify-content: center; gap: 7px; width: 100%; }
.duotone-pair canvas { width: min(44%, 100px); height: auto; aspect-ratio: 100 / 102; border-radius: 8px; }
</style>
</head>
<body>
<main class="demo">
<div class="visual-specimen" aria-hidden="true"><div class="duotone-pair"><canvas width="100" height="102"></canvas><canvas width="100" height="102"></canvas></div></div>
</main>
<script>
const [source, result] = document.querySelectorAll('canvas');
const picture = source.getContext('2d');
const tinted = result.getContext('2d');
picture.fillStyle = '#89c1da';
picture.fillRect(0, 0, 100, 102);
picture.fillStyle = '#ffe09a';
picture.beginPath();
picture.arc(70, 27, 15, 0, Math.PI * 2);
picture.fill();
function slope(color, peak, first, last) {
picture.fillStyle = color;
picture.beginPath();
picture.moveTo(first, 102);
picture.lineTo(peak[0], peak[1]);
picture.lineTo(last, 102);
picture.fill();
}
slope('#5c9c8d', [60, 37], 2, 128);
slope('#36647e', [29, 49], -20, 91);
slope('#163941', [92, 65], 26, 130);
const pixels = picture.getImageData(0, 0, 100, 102);
const dark = [40, 21, 74];
const light = [249, 173, 116];
for (let index = 0; index < pixels.data.length; index += 4) {
const luminance = (
pixels.data[index] * .2126 +
pixels.data[index + 1] * .7152 +
pixels.data[index + 2] * .0722
) / 255;
for (let channel = 0; channel < 3; channel++) {
pixels.data[index + channel] = dark[channel] + (light[channel] - dark[channel]) * luminance;
}
}
tinted.putImageData(pixels, 0, 0);
</script>
</body>
</html>Original example by UI Skills