Add detection for svgs which actually contain pngs, convert png into proper svg

This commit is contained in:
pietervdvn 2022-02-06 03:02:45 +01:00
parent 278fce8726
commit dd63ed7ab0
5 changed files with 981 additions and 2482 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

File diff suppressed because it is too large Load diff

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 50 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View file

@ -96,6 +96,26 @@ class LayerOverviewUtils {
return dict;
}
checkAllSvgs(){
const allSvgs = ScriptUtils.readDirRecSync("./assets")
.filter(path => path.endsWith(".svg"))
.filter(path => !path.startsWith("./assets/generated"))
let errCount = 0;
for (const path of allSvgs) {
const contents = readFileSync(path, "UTF8")
if (contents.indexOf("data:image/png;") < 0) {
continue;
}
console.warn("The SVG at " + path + " is a fake SVG: it contains PNG data!")
errCount++;
if(path.startsWith("./assets/svg")){
throw "A core SVG is actually a PNG. Don't do this!"
}
}
console.log("There are "+errCount+" fake svgs")
}
main(_: string[]) {
const licensePaths = new Set<string>()
@ -126,8 +146,9 @@ class LayerOverviewUtils {
const rendering = (<PointRenderingConfigJson>protolayer.mapRendering[0])
rendering.icon["mappings"] = iconsPerTheme
writeFileSync('./assets/themes/mapcomplete-changes/mapcomplete-changes.json', JSON.stringify(proto, null, " "))
}
this.checkAllSvgs()
}
private buildLayerIndex(knownImagePaths: Set<string>): Map<string, LayerConfigJson> {

View file

@ -7,6 +7,7 @@ import * as all_known_layouts from "../assets/generated/known_layers_and_themes.
import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig";
import xml2js from 'xml2js';
import ScriptUtils from "./ScriptUtils";
const sharp = require('sharp');
const template = readFileSync("theme.html", "utf8");
@ -282,7 +283,6 @@ async function main(): Promise<void>{
const manif = JSON.stringify(manifObj, undefined, 2);
writeFileSync("index.manifest", manif)
})
}
main().then(() => {