-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCanvasContrastChecker.html
815 lines (704 loc) · 23.5 KB
/
CanvasContrastChecker.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
<!DOCTYPE html>
<html>
<head>
<title>Contrast checker</title>
<style>
#footer {
min-height:7em;
}
canvas {
image-rendering: optimizeSpeed; /* Older versions of FF */
image-rendering: -moz-crisp-edges; /* FF 6.0+ */
image-rendering: -webkit-optimize-contrast; /* Safari */
image-rendering: -o-crisp-edges; /* OS X & Windows Opera (12.02+) */
-ms-interpolation-mode: nearest-neighbor; /* IE */
}
body {
background-color:white;
}
/* HTML5 color pickers */
input[type="color"] {
max-width:1.5em;
}
/* info pop-up */
#popup {
display:none;
}
<!-- info pop on hover and on focus -->
a.pop:hover #popup, a.pop:focus #popup{
position:absolute;
left: -10em;
top:1.5em;
width:9 em;
background-color:lightgray;
color:black;
border: thin solid black;
text-align:center;
display:block;
border-radius:4px;
box-shadow: 5px 5px 8px #CCC;
}
</style>
<script>
// globals
var imageLoader; // image file load input type file
var imageCanvas; // images canvas object
var imageCtx; // image context object
var normalData; // image data after load unfiltered
var imageLoaded; // has the image been loaded? If not UI is not functional
var imageScaled = true; // is the image scaled to fit the width of the display
var imageFile; // copy of image file used in case we need to rescale image
var zoom; // zoom canvas object
var displayZoom = false; // should we display the magnified canvas
var activeColor = ""; // id string of the active color1 or color2
// ***********************************************
function init() {
// input@type=file loader
imageLoader = document.getElementById('imageLoader');
imageLoader.addEventListener('change', handleImage, false);
// when the mouse leaves the canvas remove the magnified area
imageCanvas = document.getElementById("imageCanvas");
imageCanvas.addEventListener("mouseout", function(){
zoom.style.display = "none";
});
imageCanvas.addEventListener("click", setColor);
zoom = document.getElementById("zoom");
var zoomCtx = zoom.getContext("2d");
zoomCtx.mozImageSmoothingEnabled = false;
zoomCtx.webkitImageSmoothingEnabled = false;
zoomCtx.msImageSmoothingEnabled = false;
zoomCtx.imageSmoothingEnabled = false;
imageCanvas.addEventListener("mousemove", function(e){
// console.log(e);
if (!imageLoaded || !displayZoom)
return;
var pos = findPos(this);
var x = e.pageX - pos.x;
var y = e.pageY - pos.y;
var c = imageCanvas.getContext('2d');
var p = c.getImageData(x, y, 1, 1).data;
var hex = "#" + ("000000" + rgbToHex(p[0], p[1], p[2])).slice(-6);
zoomCtx.fillStyle = hex;
zoomCtx.clearRect(0,0, zoom.width, zoom.height);
//zoomCtx.fillStyle = "transparent";
zoomCtx.fillRect(0,0, zoom.width, zoom.height);
// last two 0 or 0 are location in zoom canvas last two are scale level
zoomCtx.drawImage(imageCanvas, x-10, y-10, 20, 20, 10,10, 130, 130);
// draws the cross hairs in the zoom canvas
zoomCtx.rect((zoom.width/2)-2,(zoom.height/2)-2,8,8);
zoomCtx.strokeStyle="red";
zoomCtx.lineWidth="2";
zoomCtx.stroke();
// if pointer to far to right put magnified view on the left of pointer
if (e.pageX+170 > window.innerWidth) {
zoom.style.left = e.pageX - 160 + "px"
}
else {
zoom.style.left = e.pageX + 10 + "px"
}
// if pointer to close to bottom put magnified view to top of pointer
if (e.pageY+100 > window.innerHeight) {
zoom.style.top = e.pageY - 160 + "px"
}
else {
zoom.style.top = e.pageY + 10 + "px"
}
// display the magnified area
zoom.style.display = "block";
updateColor(e);
});
// display default contrast for black on white
checkContrast();
// when the picker 1 chanegs update the eye dropper and value display for color 1
document.getElementById("inputcolor1picker").addEventListener("change", function(e) {
document.getElementById("inputcolor1").value = e.target.value;
document.getElementById("color1").style.backgroundColor = e.target.value;
checkContrast();
});
// when the color 1 input field changes
document.getElementById("inputcolor1").addEventListener("change", function(e) {
// console.log("changed");
var reg = new RegExp("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$");
if (e.target.value.match(reg)) {
document.getElementById("inputcolor1picker").value = e.target.value;
document.getElementById("color1").style.backgroundColor = e.target.value;
checkContrast();
}
});
// when the picker 2 chanegs update the eye dropper and value display for color 2
document.getElementById("inputcolor2picker").addEventListener("change", function(e) {
document.getElementById("inputcolor2").value = e.target.value;
document.getElementById("color2").style.backgroundColor = e.target.value;
checkContrast();
});
// when the color 1 input field changes
document.getElementById("inputcolor2").addEventListener("change", function(e) {
var reg = new RegExp("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$");
if (e.target.value.match(reg)) {
document.getElementById("inputcolor2picker").value = e.target.value;
document.getElementById("color2").style.backgroundColor = e.target.value;
checkContrast();
}
});
// text size toggled
document.getElementById("defaulttext").addEventListener("click", function(e) {
e.target.style.borderStyle = "inset";
e.target.setAttribute("aria-pressed","true");
document.getElementById("largetext").style.borderStyle = "outset";
document.getElementById("largetext").setAttribute("aria-pressed",false);
checkContrast();
});
// text size toggled
document.getElementById("largetext").addEventListener("click", function(e) {
e.target.style.borderStyle = "inset";
e.target.setAttribute("aria-pressed","true");
document.getElementById("defaulttext").style.borderStyle = "outset";
document.getElementById("defaulttext").setAttribute("aria-pressed",false);
checkContrast();
});
// if IE turn off the color picker (input type=color) as it is not supported
if (msie() || isSafari() ) {
document.getElementById("inputcolor1picker").style.display = "none";
document.getElementById("inputcolor2picker").style.display = "none";
}
}
// ****************************************************
// color1 button was clicked, turn on magnfication area and update color to color under mouse
// ****************************************************
function color1clicked() {
displayZoom = true;
activeColor = "color1";
}
// **********************************************
// color2 button was clicked, turn on magnfication area and update color to color under mouse
// **********************************************
function color2clicked() {
displayZoom = true;
activeColor = "color2";
}
// ***********************************************
// finds the x and y coordinates
// ***********************************************
function findPos(obj) {
var curleft = 0, curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return { x: curleft, y: curtop };
}
return undefined;
}
// ***********************************************
function rgbToHex(r, g, b) {
if (r > 255 || g > 255 || b > 255)
throw "Invalid color component";
return ((r << 16) | (g << 8) | b).toString(16);
}
// ******************************************
// user has clicked on canvas and we have selected that color and can now hide the magnified area
// ******************************************
function setColor(e) {
displayZoom = false;
activeColor = ""
zoom.style.display = "none";
}
// *******************************************
// update based on eye dropper
// called on mouseMove
// *******************************************
function updateColor(e) {
if (!imageLoaded)
return
e = e || window.event;
var pos = findPos(imageCanvas);
//console.log(e);
var x = e.pageX - pos.x;
var y = e.pageY - pos.y;
var ctx = imageCanvas.getContext('2d');
var p = ctx.getImageData(x, y, 1, 1).data;
var hex = "#" + ("000000" + rgbToHex(p[0], p[1], p[2])).slice(-6);
var average = ((p[0]+p[1]+p[2]) /3);
// console.log("right before color");
// display color values and update
if (activeColor) {
//console.log("color set");
document.getElementById("input"+ activeColor).value = hex;
document.getElementById("input"+ activeColor+"picker").value = hex;
document.getElementById(activeColor).style.backgroundColor = hex;
if (average > 127) { // dark background use light arrow
document.getElementById(activeColor).style.color = "black";
} else {
document.getElementById(activeColor).style.color = "white";
}
checkContrast();
}
}
// ******************************************
// called when images changes
// ***********************************************
function handleImage(e){
var reader = new FileReader();
reader.readAsDataURL(e.target.files[0]);
reader.onload = function(event){
var img = new Image();
img.src = event.target.result;
// delay after load because sometimes the image is not ready to be drawn and a blank screen appears.
setTimeout(function() {img.onload = displayImage(img);}, 1000);
//copy of image file so we can rescale later
imageFile = img;
}
}
// *********************************************************
// called once image is loaded from reader, this function draws to canvas
// *********************************************************
function displayImage(img) {
//console.log(img.src);
var ctx = imageCanvas.getContext('2d');
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;
var sizeX = img.width;
var sizeY = img.height;
// while the image is too width for the window scale by 90 until we find a usable value
if (imageScaled) {
while ((sizeX > winWidth-20) ) { // || (sizeY > winHeight-20) ) {
sizeX = sizeX * .90;
sizeY = sizeY * .90;
}
}
imageCanvas.width = sizeX; //img.width;
imageCanvas.height = sizeY; // img.height;
ctx.mozImageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
ctx.msImageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = false;
ctx.drawImage(img,0,0, sizeX,sizeY);
// console.log(imageCanvas.width);
if (imageCanvas.width > 0)
setTimeout(function() {normalData = ctx.getImageData(0,0,imageCanvas.width, imageCanvas.height);}, 1000);
//reset UI
document.getElementById("selectFilter").selectedIndex = 0;
imageLoaded = true;
}
// **********************************************
// really full scale image
// **********************************************
function rescaleImage() {
var ctx = imageCanvas.getContext('2d');
var img = new Image();
img.src = imageFile.src;
imageCanvas.width = img.width; //img.width;
imageCanvas.height = img.height; // img.height;
ctx.drawImage(img,0,0, img.width,img.height);
}
//*************************************************************
// Apply a user selected filter such as protanopia or grayscale
//*************************************************************
function filter() {
if (!imageLoaded) return;
var ctx = imageCanvas.getContext("2d");
// reset image to original before perfoming an filters
ctx.putImageData(normalData,0,0);
var pdata = ctx.getImageData(0,0,imageCanvas.width, imageCanvas.height);
var filter = document.getElementById("selectFilter");
var selection = filter[filter.selectedIndex].text;
if (selection == "Protanopia")
pdata = convertProtanopia(pdata);
else if (selection == "Deuteranopia")
pdata = convertDeuteranopia(pdata);
else if (selection == "Tritanopia")
pdata = convertTritanopia(pdata);
else if (selection == "Grayscale")
pdata = convertGrayscale(pdata);
else if (selection == "Invert")
pdata = convertInvert(pdata);
else if (selection == "Typical")
pdata = normalData;
// draw altered image
ctx.putImageData(pdata,0,0);
}
// ************************************************************
// protanopia simulator
// ************************************************************
function convertProtanopia(pixels) {
var d = pixels.data;
for (var i=0; i<d.length; i+=4) {
var r = d[i];
var g = d[i+1];
var b = d[i+2];
// convert to LMS
var L = (17.8824 * r) + (43.5161 * g) + (4.1193 * b);
var M = (3.4557 * r) + (27.1554 * g) + (3.8671 * b);
var S = (0.02996 * r) + (0.18431 * g) + (1.4670 * b);
// Simulate protanopia
var l = (0 * L) + (2.02344 * M) + (-2.52581 * S);
var m = (0 * L) + (1 * M) + (0 * S);
var s = (0 * L) + (0 * M) + (1 * S);
// LMS to RGB conversion
var R = (0.0809 * l) + (-0.1305 * m) + (0.116 * s);
var G = (-0.0102 * l) + (0.0540 * m) + (-0.1136 * s);
var B = (-0.0003 * l) + (-0.0041 * m) + (0.6935 * s);
// Clean up values
if (R < 0) {
R = 0;
console.log("r0");
}
if (R > 255) {
console.log("r255");
R = 255;
}
if (G < 0) {
G = 0;
console.log("g0");
}
if (G > 255) {
G = 255;
console.log("g255");
}
if (B < 0) {
B = 0;
console.log("b0");
}
if (B > 255) {
B = 255;
console.log("b255");
}
d[i] = R;
d[i+1] = G;
d[i+2] = B;
//rgb approximation
/*d[i] = .467*r + .433*g;
d[i+1] = .478*r + .412*g;
d[i+2] = .442*g + .778*b; */
d[i] = .550*r + .433*g;
d[i+1] = .550*r + .412*g;
d[i+2] = b;
}
return pixels;
}
// **************************************************
// Deuteranopia
// **************************************************
function convertDeuteranopia(pixels) {
var d = pixels.data;
for (var i=0; i<d.length; i+=4) {
var r = d[i];
var g = d[i+1];
var b = d[i+2];
// convert to LMS
var L = (17.8824 * r) + (43.5161 * g) + (4.1193 * b);
var M = (3.4557 * r) + (27.1554 * g) + (3.8671 * b);
var S = (0.02996 * r) + (0.18431 * g) + (1.4670 * b);
// Simulate deuteranopia
var l = (1 * L) + (0 * M) + (0 * S);
var m = (0.494207 * L) + (0.0 * M) + (1.24827 * S);
var s = (0 * L) + (0 * M) + (1.0 * S);
// LMS to RGB conversion
var R = (0.0809 * l) + (-0.1305 * m) + (0.116 * s);
var G = (-0.0102 * l) + (0.0540 * m) + (-0.1136 * s);
var B = (-0.0003 * l) + (-0.0041 * m) + (0.6935 * s);
// Clean up values
if (R < 0) {
R = 0;
console.log("r0");
}
if (R > 255) {
console.log("r255");
R = 255;
}
if (G < 0) {
G = 0;
console.log("g0");
}
if (G > 255) {
G = 255;
console.log("g255");
}
if (B < 0) {
B = 0;
console.log("b0");
}
if (B > 255) {
B = 255;
console.log("b255");
}
d[i] = R;
d[i+1] = G;
d[i+2] = B;
/*
d[i] = 0.625*r + 0.375*g;
d[i+1] = 0.70*r + 0.30*g;
d[i+2] = 0.30*g + .70*b;
*/
}
return pixels;
}
// **************************************************
// Tritanopia
// **************************************************
function convertTritanopia(pixels) {
var d = pixels.data;
for (var i=0; i<d.length; i+=4) {
var r = d[i];
var g = d[i+1];
var b = d[i+2];
/*
// convert to LMS
var L = (17.8824 * r) + (43.5161 * g) + (4.1193 * b);
var M = (3.4557 * r) + (27.1554 * g) + (3.8671 * b);
var S = (0.02996 * r) + (0.18431 * g) + (1.4670 * b);
// Simulate tritanopia
var l = (1.0 * L) + (0 * M) + (0 * S);
var m = (0 * L) + (1.0 * M) + (0 * S);
var s = (-0.395913 * L) + (0.801109 * M) + (0 * S);
// LMS to RGB conversion
var R = (0.0809 * l) + (-0.1305 * m) + (0.116 * s);
var G = (-0.0102 * l) + (0.0540 * m) + (-0.1136 * s);
var B = (-0.0003 * l) + (-0.0041 * m) + (0.6935 * s);
// Clean up values
if (R < 0) {
R = 0;
console.log("r0");
}
if (R > 255) {
console.log("r255");
R = 255;
}
if (G < 0) {
G = 0;
console.log("g0");
}
if (G > 255) {
G = 255;
console.log("g255");
}
if (B < 0) {
B = 0;
console.log("b0");
}
if (B > 255) {
B = 255;
console.log("b255");
}
d[i] = R;
d[i+1] = G;
d[i+2] = B;
*/
d[i] = 0.972*r + 0.112*g + (-0.084*b);
d[i+1] = 0.022*r + 0.818*g + 0.160*b;
d[i+2] = 0.063*r + 0.881*g + 0.182*b;
}
return pixels;
}
// *************************************************
function convertGrayscale(pixels) {
var d = pixels.data;
for (var i=0; i<d.length; i+=4) {
var r = d[i];
var g = d[i+1];
var b = d[i+2];
var average = (d[i] + d[i+1] + d[i+2] ) /3;
d[i] = average;
d[i+1] = average;
d[i+2] = average;
}
return pixels;
}
// *************************************************
function convertInvert(pixels) {
var d = pixels.data;
for (var i=0; i<d.length; i+=4) {
var r = 255 - d[i];
var g = 255 - d[i+1];
var b = 255 - d[i+2];
if(r < 0) r = 0;
if(g < 0) g = 0;
if(b < 0) b = 0;
d[i] = r
d[i+1] = g
d[i+2] = b
}
return pixels;
}
// *************************************************
function scaleImage(e) {
if (e.checked) {
imageScaled = true;
} else {
imageScaled = false;
}
displayImage(imageFile);
}
// **************************************************
function saveCopy() {
if (!imageLoaded) return;
var dataURL = imageCanvas.toDataURL('image/png');
document.getElementById('save').href = dataURL;
}
// ****************************************************************
// Is the IE browser in use?
// *****************************************************************
function msie() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
var trident = ua.indexOf('Trident/');
if ((trident > 0) || (msie > 0) )
return true;
else
return false;
}
// ****************************************************************
function isSafari() {
return navigator.vendor && navigator.vendor.indexOf('Apple') > -1 &&
navigator.userAgent && !navigator.userAgent.match('CriOS');
}
// **************************************************************
// set contrast ration of text
// **************************************************************
function checkContrast()
{
var color1, color2; // fields
var l1; // higher value
var l2; // lower value
var l1R, l1G, l1B, l2R, l2G, l2B;
var txtSizeOp; // large or default text string
var result; // pass or fail string
color1 = document.getElementById('inputcolor1').value;
color2 = document.getElementById('inputcolor2').value;
if (document.getElementById("defaulttext").getAttribute("aria-pressed") == "true")
txtSizeOp = "default";
else
txtSizeOp = "large";
// remove # sign from field value
if (color2.indexOf('#') == 0)
color2 = color2.substr(1, color2.length-1);
if (color1.indexOf('#') == 0)
color1 = color1.substr(1, color1.length-1);
//Linearised R (for example) = (R/FS)^2.2 where FS is full scale value (255
//for 8 bit color channels). L1 is the higher value (of text or background)
//alert(parseInt("0x"+color1.substr(0,2)));
//Math.pow(n,x);
l1R = parseInt("0x"+color1.substr(0,2))/255;
if (l1R <= 0.03928) {
l1R = l1R/12.92;
}
else {
l1R = Math.pow(((l1R+0.055)/1.055),2.4);
}
l1G = parseInt("0x"+color1.substr(2,2))/255;
if (l1G <= 0.03928) {
l1G = l1G/12.92;
}
else {
l1G = Math.pow(((l1G+0.055)/1.055),2.4);
}
l1B = parseInt("0x"+color1.substr(4,2))/255;
if (l1B <= 0.03928) {
l1B = l1B/12.92;
}
else {
l1B = Math.pow(((l1B+0.055)/1.055),2.4);
}
l2R = parseInt("0x"+color2.substr(0,2))/255;
if (l2R <= 0.03928) {
l2R = l2R/12.92;
}
else {
l2R = Math.pow(((l2R+0.055)/1.055),2.4);
}
l2G = parseInt("0x"+color2.substr(2,2))/255;
if (l2G <= 0.03928) {
l2G = l2G/12.92;
}
else {
l2G = Math.pow(((l2G+0.055)/1.055),2.4);
}
l2B = parseInt("0x"+color2.substr(4,2))/255;
if (l2B <= 0.03928) {
l2B = l2B/12.92;
}
else {
l2B = Math.pow(((l2B+0.055)/1.055),2.4);
}
//where L is luminosity and is defined as
l1 = (.2126*l1R) + (.7152*l1G) + (.0722*l1B); //using linearised R, G, and B value
l2 = (.2126*l2R) + (.7152*l2G) + (.0722*l2B); //using linearised R, G, and B value
//and L2 is the lower value.
l1 = l1 + .05;
l2 = l2 + .05;
// l1 should be larger - switch if not
if (l1 < l2) {
temp = l1;
l1 = l2;
l2 = temp;
}
l1 = l1/l2;
// to one decimal place
l1 = l1.toFixed(1);
// display contrast ratio
document.getElementById('contrast').value = l1.toString()+":1";
if (txtSizeOp == "large") {
if (l1 > 3)
result = "Pass A/AA";
else
result = "Fail A/AA";
} else { // default text size
if (l1 > 4.5)
result = "Pass A/AA";
else
result = "Fail A/AA";
}
// display pass/fail result
document.getElementById('output1').textContent = result;
document.getElementById("sample").style.color = "#"+color1;
document.getElementById("sample").style.backgroundColor = "#" + color2;
} // checkContrast
// ********************** end scripts ***********************
</script>
</head>
<body onload="init();">
<div id="maincontainer" style="max-width:100%;" >
<div id="toolbar1">
<label for="imageLoader">Image:</label>
<input type="file" id="imageLoader" name="imageLoader"/>
<label for="scale">Scale?</label><input onclick="scaleImage(this);" id="scale" type="checkbox" checked/>
<select title="Select filter" id="selectFilter">
<option value="typical">Typical</option>
<option value="protanopia">Protanopia</option>
<option value="deuteranopia">Deuteranopia</option>
<option value="tritanopia">Tritanopia</option>
<option value="grayscale">Grayscale</option>
<option value="invert">Invert</option>
</select>
<button onclick="filter();">Filter</button>
<a tabindex="0" href="javascript:void();" role="button" download="imagecopy.png" id="save" onclick="saveCopy();">Save Copy</a>
<label style="margin-left:1em;" for="output1">Conforms?</label>
<output style="padding:.1em; border:thin solid black;" id="output1">TBD</output>
<a aria-label="Info" aria-describedby="popup" class="pop" id="info" style="position:relative; font-size:large;" href="#" role="button"><span id="popup">WCAG 2 A/AA conformance requires a contrast ratio of 4.5:1 for default size text & 3:1 for text that is 14pt+ and bold or 18pt+.</span><i>i</i></a>
</div>
<div id="toolbar2">
Color 1:
<button title="eye dropper color 1" id="color1" style="color: white; min-width:1.5em; min-height:1.5em; background-color:black;" onclick="color1clicked();">⇱</button>
<input pattern="^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$" title="Color 1 value" size="6" id="inputcolor1" type="text" value="#000000"/>
<input title="Color 1 pickter" id="inputcolor1picker" type="color" value="#000000"/>
Color 2:
<button title="eye dropper colro 2" onclick="color2clicked();" id="color2" style="color:black; min-width:1.5em; min-height:1.5em; background-color:white;">⇱</button>
<input pattern="^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$" title="Color 2 value" size="6" id="inputcolor2" type="text" value="#FFFFFF"/>
<input title="Color 2 picker" id="inputcolor2picker" type="color" value="#FFFFFF"/>
<output id="sample" style="border:thin solid black; padding-left:.5em; margin-left:.5em; margin-right:.5em; padding-right:.5em;">Sample</output>
<label for="contrast">Contrast:</label>
<input type="text" size="4" id="contrast" />
<label>Text:</label>
<button aria-pressed="true" aria-label="default text size" id="defaulttext" style="border-style:inset;" >Default</button>
<button aria-pressed="false" aria-label="large text size" id="largetext">Large</button>
</div>
<div id="workarea">
<canvas id="imageCanvas" name="imageCanvas"style=""></canvas>
<canvas id="zoom" width="150" height="150" style="position:absolute; top:0; left:0; display:none"></canvas>
<div id="footer">
</div>
</div> <!-- workarea -->
</div> <!-- maincontainer -->
</body>
</html>