1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20:
21: include __DIR__ . '/header.php';
22:
23: $xoops = Xoops::getInstance();
24:
25: $xoops->header();
26:
27: $admin_page = new \Xoops\Module\Admin();
28: $admin_page->displayNavigation('index.php');
29:
30: $bg = $xoops->getModuleConfig('qrcode_bgcolor', 'qrcode');
31: $bg = getBrightness($bg);
32:
33: $fg = $xoops->getModuleConfig('qrcode_fgcolor', 'qrcode');
34: $fg = getBrightness($fg);
35:
36: $contrastMessage = _MI_QRCODE_CONTRAST_OK;
37: $contrastStatus = 'accept';
38:
39: if ($bg < $fg) {
40: $contrastMessage = _MI_QRCODE_CONTRAST_INVERSE;
41: $contrastStatus = 'error';
42: } elseif (($bg-$fg) < 100) {
43: $contrastMessage = _MI_QRCODE_CONTRAST_ERROR;
44: $contrastStatus = 'error';
45: }
46: $admin_page->addConfigBoxLine($contrastMessage, $contrastStatus);
47: $admin_page->displayIndex();
48:
49: $xoops->footer();
50:
51: 52: 53: 54: 55: 56: 57:
58: function getBrightness($color)
59: {
60: $rgb = normalizeColor($color);
61:
62:
63: $brightness = ($rgb['r']*0.2126 + $rgb['g']*0.7152 + $rgb['b']*0.0722);
64: return $brightness + 0.00001;
65: }
66:
67: 68: 69: 70: 71: 72: 73:
74: function normalizeColor($color)
75: {
76: $color = preg_replace('/[^a-fA-F0-9]+/', '', $color);
77: $color = substr('000000'.$color, -6);
78: $rgb = array(
79: 'r' => hexdec(substr($color, 0, 2)),
80: 'g' => hexdec(substr($color, 2, 2)),
81: 'b' => hexdec(substr($color, 4, 2)),
82: );
83: return $rgb;
84: }
85: