tileblaster 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builtins/convert.js +57 -0
- package/docs/config.md +15 -0
- package/package.json +1 -1
- package/tileblaster.js +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// convert
|
|
2
|
+
module.exports = function convert({ opts, data }, next){
|
|
3
|
+
const sharp = this.lib.sharp;
|
|
4
|
+
const debug = this.lib.debug;
|
|
5
|
+
|
|
6
|
+
// check if sharp is available
|
|
7
|
+
if (typeof sharp === "undefined") {
|
|
8
|
+
debug.warn("Convert: Sharp dependency is missing.");
|
|
9
|
+
return next();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// check if tile should be optimized
|
|
13
|
+
if (!["png","jpeg","jpg","gif"].includes(data.tile.type)) {
|
|
14
|
+
debug.warn("Convert: Unsupported file type: %s", data.tile.type);
|
|
15
|
+
return next();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Promise.allSettled(["jpeg","png"].map(function(method){
|
|
19
|
+
return new Promise(function(resolve, reject) {
|
|
20
|
+
if (!opts[method]) return reject();
|
|
21
|
+
|
|
22
|
+
// copy primary tile
|
|
23
|
+
const tile = { ...data.tile };
|
|
24
|
+
|
|
25
|
+
// fixme: find suitable tile in tiles
|
|
26
|
+
sharp(tile.buffer).toFormat(method, opts[method]).toBuffer(function(err, buffer, info){
|
|
27
|
+
if (err) {
|
|
28
|
+
debug.error("Convert: %s", err);
|
|
29
|
+
return reject();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// fix tile
|
|
33
|
+
tile.buffer = buffer;
|
|
34
|
+
tile.path = tile.path+"."+method;
|
|
35
|
+
tile.type = method;
|
|
36
|
+
tile.mimetype = "image/"+method;
|
|
37
|
+
tile.headers = { ...tile.headers };
|
|
38
|
+
|
|
39
|
+
// add to tile stack
|
|
40
|
+
data.tiles.unshift(tile);
|
|
41
|
+
|
|
42
|
+
// set primary if smaller
|
|
43
|
+
if (buffer.length < data.tile.buffer.length) {
|
|
44
|
+
debug.info("Converted '%s': -%db", tile.path.magenta, data.tile.buffer.length-buffer.length);
|
|
45
|
+
data.tile = tile;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
resolve();
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
});
|
|
53
|
+
})).then(function(){
|
|
54
|
+
next();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
};
|
package/docs/config.md
CHANGED
|
@@ -275,6 +275,21 @@ Edit vectortiles
|
|
|
275
275
|
|
|
276
276
|
**Not yet implemented** FIXME
|
|
277
277
|
|
|
278
|
+
#### `convert`
|
|
279
|
+
|
|
280
|
+
Convert raster tiles to differen Formats.
|
|
281
|
+
The resulting tile with the smallest size becomes the main tile.
|
|
282
|
+
|
|
283
|
+
``` js
|
|
284
|
+
{
|
|
285
|
+
builtin: "convert",
|
|
286
|
+
jpeg: {
|
|
287
|
+
quality: 90,
|
|
288
|
+
mozjpeg: true,
|
|
289
|
+
},
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
278
293
|
#### `modernize`
|
|
279
294
|
|
|
280
295
|
Convert JPEG or PNG raster tiles to WebP or AVIF.
|
package/package.json
CHANGED
package/tileblaster.js
CHANGED
|
@@ -33,7 +33,7 @@ const tileblaster = module.exports = function tileblaster(config){
|
|
|
33
33
|
|
|
34
34
|
// load builtins
|
|
35
35
|
self.builtins = {};
|
|
36
|
-
self.loadBuiltins([ "cors", "parse", "check", "noop", "tileserver", "versatiles", "pmtiles", "mbtiles", "edit", "compress", "cache", "deliver", "dump", "modernize", "optimize", "sharp" ]);
|
|
36
|
+
self.loadBuiltins([ "cors", "parse", "check", "noop", "tileserver", "versatiles", "pmtiles", "mbtiles", "edit", "compress", "cache", "deliver", "dump", "modernize", "optimize", "convert", "sharp" ]);
|
|
37
37
|
|
|
38
38
|
// assemble task lists for maps
|
|
39
39
|
self.maps = {};
|