forked from opengeogroep/safetymapsDBK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
images2base64.js
64 lines (51 loc) · 2.12 KB
/
images2base64.js
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
/**
* Copyright (c) 2014 B3Partners B.V. ([email protected])
*
* This file is part of safetymapDBK
*
* safetymapDBK is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* safetymapDBK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with safetymapDBK. If not, see <http://www.gnu.org/licenses/>.
*
*/
var path = require('path');
var fs = require('fs');
/**
* Writes public/js/dbkjs/images_base64.js
*
* Include the above file to enable inline images, otherwise the regular files will be used.
*/
var imagesBase64 = {};
/* directory to process can be specified on command line, use "nodeless_output" to allow
* images to be overridden in nodeless:config directory from config.json used by nodeless.js
*/
var startDir = process.argv.length > 2 ? process.argv[2] : "public";
var imagesDir = path.resolve(__dirname, startDir + "/images");
var ignore = ["brandweer-nederland_alpha_shaded.png", "brandweer-nederland_alpha_shaded-s.png", "doiv_logo_def.png", "missing.gif",
"MNarrow.png", "overview_replacement.gif"];
function convertRecursive(dir, id) {
var files = fs.readdirSync(dir);
for(var f in files) {
var fn = files[f];
var stats = fs.statSync(dir + '/' + fn);
if(stats.isFile()) {
if(ignore.indexOf(fn) == -1) {
console.log(id + fn);
imagesBase64[id + fn] = "data:image/png;base64," + new Buffer(fs.readFileSync(dir + '/' + fn)).toString('base64');
}
} else if(stats.isDirectory()) {
convertRecursive(dir + '/' + fn , id + fn + '/');
}
}
}
convertRecursive(imagesDir, "images/");
fs.writeFileSync(path.resolve(__dirname, startDir + '/js/dbkjs/images_base64.js'), "var imagesBase64 = " + JSON.stringify(imagesBase64));