双色调
Duotone
把图像的暗部映射到一种颜色,亮部映射到另一种颜色。
适用场景
统一多张图片的品牌配色,或营造海报式的编辑风格。 同一组图使用相同的暗部色和亮部色,然后逐张检查最重要的主体是否仍容易辨认。
应用示例
社区报给同一组口述史的三张肖像统一使用靛蓝暗部和淡赭色亮部。原片的光线各不相同,处理后仍能辨认不同的面孔,也一眼看出它们属于同一专栏。
AI 提示词
给【目标图片】加双色调。把归一化亮度映射到两种品牌色之间,再用曲线保住关键细节。仅处理图片图层,文字单独呈现并保证可读。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>双色调</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>UI Skills 原创示例