color verde inscripciones

This commit is contained in:
David Arranz 2022-09-15 13:29:18 +02:00
parent 608800823a
commit 4183326b86
2 changed files with 25 additions and 2 deletions

View File

@ -4,6 +4,29 @@ const moment = require("moment");
const config = require("../config");
const luma = (color) => { // color can be a hx string or an array of RGB values 0-255
const rgb = (typeof color === 'string') ? hexToRGBArray(color) : color;
return (0.2126 * rgb[0]) + (0.7152 * rgb[1]) + (0.0722 * rgb[2]); // SMPTE C, Rec. 709 weightings
}
const hexToRGBArray = (color) => {
if (color.length === 3)
color = color.charAt(0) + color.charAt(0) + color.charAt(1) + color.charAt(1) + color.charAt(2) + color.charAt(2);
else if (color.length !== 6)
console.debug('Invalid hex color: ' + color);
const rgb = [];
for (var i = 0; i <= 2; i++)
rgb[i] = parseInt(color.substr(i * 2, 2), 16);
return rgb;
}
const calculateContrastingColor = (color) => {
const _color = (typeof color === 'string') ? color.replace('#', '') : color;
return (luma(_color) >= 165) ? '#000' : '#fff';
}
module.exports.getInscriptionQRCodeUrl = function (inscriptionId) {
return encodeURI(`${config.server.public_url}/inscriptions/${inscriptionId}/qrimage`);
};
@ -34,7 +57,7 @@ module.exports.getInscriptionQRCode = function (params) {
options = _.assign(options, {
color: {
light: params.color ? colourNameToHex(params.color) : "#000000",
dark: "#ffffff",
dark: calculateContrastingColor(params.color), //"#ffffff",
},
});
}

View File

@ -42,7 +42,7 @@ function _generateMarketingDTO(dataInscription) {
inscriptionDTO.validated = inscription.validated;
inscriptionDTO.reservation_code = reservation ? reservation.reservation_code : null;
inscriptionDTO.color = reservation ? reservation.color : 'green';
inscriptionDTO.color = reservation ? reservation.color : "darkgreen";
inscriptionDTO.description = (reservation ? reservation.description : "Entrada").toUpperCase();
inscriptionDTO.qrConfig = null;
inscriptionDTO.qrCode = null;