-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocumentation.html
206 lines (183 loc) · 5.16 KB
/
documentation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!doctype html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport'
content='width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title>Get dominant color</title>
<link rel='stylesheet' href='./css/style.css'>
<style>
@font-face {
font-family: Roboto Mono;
font-style: normal;
font-weight: 400;
src: url(https://stackedit.io/static/fonts/RobotoMono-Regular.0b6a547.woff) format("woff")
}
@font-face {
font-family: Roboto Mono;
font-style: normal;
font-weight: 600;
src: url(https://stackedit.io/static/fonts/RobotoMono-Bold.819f3b2.woff) format("woff")
}
pre, code {
font-family: monospace, monospace;
font-size: 1em
}
h1, h2 {
margin: 1.8em 0;
line-height: 1.33
}
h1:after, h2:after {
content: "";
display: block;
position: relative;
top: .33em;
border-bottom: 1px solid hsla(0, 0%, 50%,
.33)
}
code, pre {
font-family: Roboto Mono, Lucida Sans Typewriter, Lucida Console, monaco, Courrier, monospace;
font-size: .85em
}
code *, pre * {
font-size: inherit
}
code {
background-color: rgba(0, 0, 0,
.05);
border-radius: 3px;
padding: 2px 4px
}
pre > code {
background-color: rgba(0, 0, 0,
.05);
display: block;
padding: .5em;
-webkit-text-size-adjust: none;
overflow-x: auto;
white-space: pre
}
table {
background-color: transparent;
border-collapse: collapse;
border-spacing: 0
}
td, th {
border-right: 1px solid #dcdcdc;
padding: 8px 12px
}
td:last-child, th:last-child {
border-right: 0
}
td {
border-top: 1px solid #dcdcdc
}
</style>
</head>
<body>
<header>
<ul>
<li><a href='/dominant-color/'>Home</a></li>
<li class='active'><a href='/dominant-color/documentation.html'>Documentation</a></li>
<li>
<a href='#'>Examples</a>
<ul>
<li><a href='/dominant-color/examples/palette'>Palette</a></li>
<li><a href='/dominant-color/examples/music-app'>Music app</a></li>
</ul>
</li>
<li><a href='https://github.com/rtcoder/dominant-color/releases' target='_blank'>Download</a></li>
</ul>
</header>
<div class='container'>
<h1 id='dominant-color'>Dominant color</h1>
<p>Get dominant color from images using only JavaScript</p>
<h2 id='installation'>Installation</h2>
<pre><code>npm i @rtcoder/dominant-color
</code></pre>
<h2 id='usage'>Usage</h2>
<pre><code>import {getDominantColor} from "@rtcoder/dominant-color";
const img = document.querySelector('img');
getDominantColor(img, {
downScaleFactor: 1,
skipPixels: 0,
colorsPaletteLength: 5,
paletteWithCountOfOccurrences: false,
colorFormat: 'rgb',
callback: (color, palette) => {
// your code here
}
});
</code></pre>
<h2 id='config-options'>Config options</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>downScaleFactor</code></td>
<td>number</td>
<td>1</td>
<td>factor of scale down of image, recommended to use for many large images</td>
</tr>
<tr>
<td><code>skipPixels</code></td>
<td>number</td>
<td>0</td>
<td>when larger than 0, skips every n pixels of while determine dominant color, recommended to use for large
images
</td>
</tr>
<tr>
<td><code>colorsPaletteLength</code></td>
<td>number</td>
<td>5</td>
<td>length of returned palette of colors</td>
</tr>
<tr>
<td><code>paletteWithCountOfOccurrences</code></td>
<td>boolean</td>
<td>false</td>
<td>determines whether to return colors with the number of occurrences</td>
</tr>
<tr>
<td><code>colorFormat</code></td>
<td>string</td>
<td>‘rgb’</td>
<td>defines the format of the returned colors, available values are ‘rgb’, ‘hsl’ and ‘hex’</td>
</tr>
<tr>
<td><code>callback</code></td>
<td>function</td>
<td>[empty function]</td>
<td>callback function</td>
</tr>
</tbody>
</table>
<h2 id='interfaces'>Interfaces</h2>
<pre><code>type ColorFormat = 'rgb' | 'hsl' | 'hex';
interface PrimaryColor {
color: string;
count: number;
}
interface DominantColorOptions {
downScaleFactor: number;
skipPixels: number;
colorsPaletteLength: number;
paletteWithCountOfOccurrences: boolean;
colorFormat: ColorFormat;
callback: DominantColorCallback;
}
type DominantColorCallback = (dominant: string, colorsPalette: (string[]) | (PrimaryColor[])) => void;
function getDominantColor(element: HTMLImageElement, options: Partial<DominantColorOptions>): void
</code></pre>
</div>
</body>
</html>