mirror of
https://github.com/lenaschimmel/queerallyear
synced 2024-11-10 05:54:13 +00:00
Shadow is now selectable
This commit is contained in:
parent
7c52b1adf4
commit
6884267808
5 changed files with 275 additions and 1103 deletions
|
@ -14,7 +14,7 @@ const resolve = require('path').resolve;
|
|||
const logo = fs.readFileSync("../../web/img/logo.svg").toString();
|
||||
const logo_with_shadow = fs.readFileSync("../../web/img/logo_with_shadow.svg").toString();
|
||||
const mainlogo = logo.substring(logo.indexOf("?>") + 2).replace('id="Ebene_1"', 'id="mainlogo"');
|
||||
const smalllogo = logo_with_shadow.substring(logo.indexOf("?>") + 2).replace('id="Ebene_1"', 'id="smalllogo"');
|
||||
const smalllogo = logo_with_shadow.substring(logo_with_shadow.indexOf("?>") + 2).replace('id="Ebene_1"', 'id="smalllogo"');
|
||||
|
||||
var fragments = {};
|
||||
|
||||
|
@ -85,40 +85,44 @@ for (const key in pages) {
|
|||
app.use(express.static('../../web/'));
|
||||
|
||||
async function initSvg(withshadow) {
|
||||
dom = "";
|
||||
var dom = "";
|
||||
if(withshadow)
|
||||
dom = await JSDOM.fromFile("../../web/img/logo_with_shadow.svg", {} );
|
||||
else
|
||||
dom = await JSDOM.fromFile("../../web/img/logo.svg", {} );
|
||||
var doc = dom.window.document;
|
||||
//var gradients = dom.window.document.querySelector("defs");
|
||||
var defs = doc.getElementsByTagName("defs").item(0);
|
||||
return new GradientSvg(defs);
|
||||
return new GradientSvg(dom);
|
||||
}
|
||||
|
||||
//gradientsFutureWithShadow = initSvg(true);
|
||||
gradientsFutureWithShadow = initSvg(true);
|
||||
gradientsFuture = initSvg(false);
|
||||
|
||||
app.get('/design/download', async function (req, res) {
|
||||
var flag = req.query.flag;
|
||||
var type = req.query.type;
|
||||
// var withshadow = req.query.type;
|
||||
var withshadow = req.query.withshadow;
|
||||
var width = parseInt(req.query.width) || 1920;
|
||||
|
||||
console.log("Building " + flag + ", " + type);
|
||||
if(type == "pdf" && withshadow) {
|
||||
res.status(500).send("Sorry, pdf-Ausgabe funktioniert derzeit nicht mit aktivierten Schatten.");
|
||||
return;
|
||||
}
|
||||
|
||||
var prettyFileName = "QueerAllYear_" + flag + "_w" + width + (withshadow ? "_withshadow" : "") + "." + type;
|
||||
|
||||
|
||||
console.log("Building " + flag + ", " + type + ", withShadow: " + withshadow);
|
||||
|
||||
//var gradients = withshadow ? (await gradientsFutureWithShadow) : (await gradientsFuture);
|
||||
var gradients = await gradientsFuture;
|
||||
var gradients = withshadow ? (await gradientsFutureWithShadow) : (await gradientsFuture);
|
||||
gradients.changeGradients(flags.allFlags[flag]);
|
||||
var start = '<!--?xml version="1.0" encoding="UTF-8" standalone="no"?--><html><head></head><body>';
|
||||
var end = '</body></html>';
|
||||
|
||||
if(type == "svg") {
|
||||
res.send(dom.serialize().replace(start, "").replace(end, ""));
|
||||
res.setHeader('Content-Type', 'image/svg+xml');
|
||||
res.setHeader('Content-Disposition','attachment; filename="'+prettyFileName+'"');
|
||||
res.send(gradients.svgString());
|
||||
} else if(type == "pdf" || type == "png" || type == "jpg") {
|
||||
try {
|
||||
const filenameBase = resolve("tmp/tmp" + Math.random().toString());
|
||||
fs.writeFileSync(filenameBase + ".svg", dom.serialize().replace(start, "").replace(end, ""));
|
||||
fs.writeFileSync(filenameBase + ".svg", gradients.svgString());
|
||||
const inkscape = process.env.inkscape || "inkscape";
|
||||
|
||||
extraParams = "";
|
||||
|
@ -146,7 +150,10 @@ app.get('/design/download', async function (req, res) {
|
|||
console.log("Executung: " + command);
|
||||
const { stdout, stderr } = await exec(command);
|
||||
}
|
||||
|
||||
if(type == "pdf") res.setHeader('Content-Type', 'application/pdf');
|
||||
if(type == "png") res.setHeader('Content-Type', 'image/png');
|
||||
if(type == "jpg") res.setHeader('Content-Type', 'image/jpeg');
|
||||
res.setHeader('Content-Disposition','attachment; filename="'+prettyFileName+'"');
|
||||
res.sendFile(filenameBase + "." + type);
|
||||
} catch(e) {
|
||||
res.status(500).send("Sorry, Fehler beim Erstellen der "+type+"-Datei! " + e.toString());
|
||||
|
|
|
@ -2,8 +2,7 @@ const GradientSvg = require('./recolor.js');
|
|||
const flags = require('./flags.js');
|
||||
const util = require('util');
|
||||
|
||||
var defs = window.document.getElementsByTagName("defs").item(0);
|
||||
gradientSvg = new GradientSvg(defs);
|
||||
gradientSvg = new GradientSvg(window);
|
||||
|
||||
window.queer = {};
|
||||
window.queer.showflag = function (flagname) {
|
||||
|
|
|
@ -7,9 +7,9 @@ function sleep(milliseconds) {
|
|||
|
||||
var method = GradientSvg.prototype;
|
||||
|
||||
// the parameter "defs" must be the DOM element with tag "defs" from the SVG file.
|
||||
function GradientSvg(defs) {
|
||||
this.defs = defs;
|
||||
function GradientSvg(dom) {
|
||||
this.dom = dom;
|
||||
this.defs = dom.window.document.getElementsByTagName("defs").item(0);
|
||||
this.rangesL = {};
|
||||
this.rangesS = {};
|
||||
|
||||
|
@ -18,8 +18,8 @@ function GradientSvg(defs) {
|
|||
|
||||
this.originalColors = {};
|
||||
|
||||
for (let i = 0; i < defs.children.length; i++) {
|
||||
const gradient = defs.children.item(i);
|
||||
for (let i = 0; i < this.defs.children.length; i++) {
|
||||
const gradient = this.defs.children.item(i);
|
||||
var id = gradient.id;
|
||||
if (id.length == 3) {
|
||||
var letter = id.substring(0,2);
|
||||
|
@ -56,6 +56,12 @@ function GradientSvg(defs) {
|
|||
}
|
||||
}
|
||||
|
||||
method.svgString = function() {
|
||||
const start = '<!--?xml version="1.0" encoding="UTF-8" standalone="no"?--><html><head></head><body>';
|
||||
const end = '</body></html>';
|
||||
return this.dom.serialize().replace(start, "").replace(end, "");
|
||||
}
|
||||
|
||||
method.changeGradients = async function(flag, animate = false) {
|
||||
for (let i = 0; i < this.defs.children.length; i++) {
|
||||
const gradient = this.defs.children.item(i);
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
<label for="width">Breite in Pixeln</label>
|
||||
<input type="text" name="width" id="width" maxlength="30" value="1920">
|
||||
<br>
|
||||
<!--
|
||||
|
||||
<label for="withshadow">Schatten</label>
|
||||
<input type="checkbox" name="withshadow" id="withshadow">
|
||||
<br>
|
||||
-->
|
||||
|
||||
<label for="flag">Flagge</label>
|
||||
<select name="flag" id="flagselect" onchange="queer.flagSelected();">
|
||||
$FLAGS
|
||||
|
|
File diff suppressed because it is too large
Load diff
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 26 KiB |
Loading…
Reference in a new issue