canvas实现对图片进行素描颜色替换效果代码

代码语言:html

所属分类:其他

代码描述:canvas实现对图片进行素描颜色替换效果代码,可上传图文对图片进行黑白素描,颜色替换等效果。

代码标签: canvas 图片 素描 颜色 替换

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">

<style>
*{
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	font-size: calc(16px + (24 - 16) * (100vw - 320px) / (2560 - 320));
	--bg: #737a8c;
	--buttonBg: #2762f3;
	--buttonHoverBg: #0c48db;
	--formBg: #fff;
	--inputBorder: #abafba;
	--inputBg: #fff;
	--inputDisableBg: #e3e4e8;
	--pColor: #17181c;
}
body, button, input {
	color: var(--pColor);
	font: 1em/1.5 "Hind", system-ui, -apple-system, sans-serif;
}
body, .upload-btn {
	overflow: hidden;
}
body {
	background: var(--bg);
	display: flex;
	flex-direction: column-reverse;
	height: 100vh;
}
aside, button, canvas, input, main, .upload-btn input[type=file] {
	width: 100%;
}
aside {
	background: var(--formBg);
	box-shadow: 0 0 0.25em hsla(223,10%,10%,0.5);
	overflow: auto;
}
button, input {
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
}
button, input[type=color], input[type=file] {
	cursor: pointer;
}
button:hover, button:focus, .btn-link:hover, .btn-link:focus, input[type=file]:hover + button, input[type=file]:focus + button {
	background: var(--buttonHoverBg);
}
button, .btn-link, canvas, input, label {
	display: block;
}
button, .btn-link {
	background: var(--buttonBg);
	border-radius: 0.375em;
	color: #fff;
	margin-bottom: 1.5em;
	padding: 0.75em 1em;
	transition: background 0.1s linear;
}
button:focus, .btn-link:focus {
	outline: 0;
}
canvas {
	image-rendering: pixelated; /* as of Feb 2021, not supported in Firefox */
	object-fit: contain;
	max-height: calc(100vh - 20.375em);
}
form {
	padding: 1.5em 1.5em 0 1.5em;
}
input[type=text], input[type=file] + button, .upload-btn {
	margin-bottom: 0.75em;
}.........完整代码请登录后点击上方下载按钮下载查看

网友评论0