node-tiff-to-png
node-tiff-to-png copied to clipboard
Does not seem to work in Windows (backslashes issue?)
Node version : 16.13.2 OS : Win 10 Code to reproduce:
import { normalize } from "path";
const ConvertTiff = require('tiff-to-png');
const converter = new ConvertTiff({ logLevel: 1 });
const extractDir = normalize(`${__dirname}/extracted`);
const tiffs: string[] = (await fs.readdir(extractDir))
.filter(f => f.endsWith(".tif"))
.map(f => normalize(`${__dirname}/extracted/${f}`));
console.log(`Found ${tiffs.length} files to convert...`, tiffs);
await converter.convertArray(tiffs);
Logs :
Found 2 tiffs to convert... [
'R:\\NPL\\MDPI\\extracted\\gases-01-00013-g001.tif',
'R:\\NPL\\MDPI\\extracted\\gases-01-00013-g002.tif'
]
If I log errors :
0 Converted.
2 Failed.
[
{
tiff: 'R:\\NPL\\MDPI\\extracted\\gases-01-00013-g001.tif',
target: 'R:\\NPL\\MDPI\\extracted',
filename: 'R:\\NPL\\MDPI\\extracted/gases-01-00013-g001_%d.png',
error: Error: Command failed: convert R:\NPL\MDPI\extracted\gases-01-00013-g001.tif R:\NPL\MDPI\extracted/gases-01-00013-g001_%d.png
Invalid Parameter - R:\NPL\MDPI\extracted
at ChildProcess.exithandler (node:child_process:397:12)
at ChildProcess.emit (node:events:390:28)
at ChildProcess.emit (node:domain:475:12)
at maybeClose (node:internal/child_process:1064:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
killed: false,
code: 4,
signal: null,
cmd: 'convert R:\\NPL\\MDPI\\extracted\\gases-01-00013-g001.tif R:\\NPL\\MDPI\\extracted/gases-01-00013-g001_%d.png'
}
},
{
tiff: 'R:\\NPL\\MDPI\\extracted\\gases-01-00013-g002.tif',
target: 'R:\\NPL\\MDPI\\extracted',
filename: 'R:\\NPL\\MDPI\\extracted/gases-01-00013-g002_%d.png',
error: Error: Command failed: convert R:\NPL\MDPI\extracted\gases-01-00013-g002.tif R:\NPL\MDPI\extracted/gases-01-00013-g002_%d.png
Invalid Parameter - R:\NPL\MDPI\extracted
at ChildProcess.exithandler (node:child_process:397:12)
at ChildProcess.emit (node:events:390:28)
at ChildProcess.emit (node:domain:475:12)
at maybeClose (node:internal/child_process:1064:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
killed: false,
code: 4,
signal: null,
cmd: 'convert R:\\NPL\\MDPI\\extracted\\gases-01-00013-g002.tif R:\\NPL\\MDPI\\extracted/gases-01-00013-g002_%d.png'
}
}
]
The TIF files are present in the given location, and I can open them and view them so they are not corrupted.
I suspect this is a problem with mixed backslashes and forward slashes, despite the use of path.normalize
: R:\NPL\MDPI\extracted/gases-01-00013-g001_%d.png