Merge pull request #165 from C4illin/fix/#157/resize-when-converting-to-ico
This commit is contained in:
commit
698cce58ce
9 changed files with 36 additions and 43 deletions
|
|
@ -137,7 +137,7 @@ export async function convert(
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
resolve("Done");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { exec } from "node:child_process";
|
import { exec } from "node:child_process";
|
||||||
|
|
||||||
|
|
||||||
// This could be done dynamically by running `ffmpeg -formats` and parsing the output
|
// This could be done dynamically by running `ffmpeg -formats` and parsing the output
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
|
|
@ -692,7 +691,16 @@ export async function convert(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const command = `ffmpeg -i "${filePath}" "${targetPath}"`;
|
let extra = "";
|
||||||
|
let message = "Done";
|
||||||
|
|
||||||
|
if (convertTo === "ico") {
|
||||||
|
// make sure image is 256x256 or smaller
|
||||||
|
extra = `-filter:v "scale='min(256,iw)':min'(256,ih)':force_original_aspect_ratio=decrease"`;
|
||||||
|
message = "Done: resized to 256x256";
|
||||||
|
}
|
||||||
|
|
||||||
|
const command = `ffmpeg -i "${filePath}" ${extra} "${targetPath}"`;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(command, (error, stdout, stderr) => {
|
exec(command, (error, stdout, stderr) => {
|
||||||
|
|
@ -708,7 +716,7 @@ export async function convert(
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
resolve(message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ export function convert(
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
resolve("Done");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ export function convert(
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
resolve("Done");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,13 @@
|
||||||
import { normalizeFiletype } from "../helpers/normalizeFiletype";
|
import { normalizeFiletype } from "../helpers/normalizeFiletype";
|
||||||
import {
|
import { convert as convertassimp, properties as propertiesassimp } from "./assimp";
|
||||||
convert as convertassimp,
|
import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg";
|
||||||
properties as propertiesassimp,
|
import { convert as convertGraphicsmagick, properties as propertiesGraphicsmagick } from "./graphicsmagick";
|
||||||
} from "./assimp";
|
import { convert as convertLibjxl, properties as propertiesLibjxl } from "./libjxl";
|
||||||
import {
|
import { convert as convertPandoc, properties as propertiesPandoc } from "./pandoc";
|
||||||
convert as convertFFmpeg,
|
import { convert as convertresvg, properties as propertiesresvg } from "./resvg";
|
||||||
properties as propertiesFFmpeg,
|
|
||||||
} from "./ffmpeg";
|
|
||||||
import {
|
|
||||||
convert as convertGraphicsmagick,
|
|
||||||
properties as propertiesGraphicsmagick,
|
|
||||||
} from "./graphicsmagick";
|
|
||||||
import {
|
|
||||||
convert as convertLibjxl,
|
|
||||||
properties as propertiesLibjxl,
|
|
||||||
} from "./libjxl";
|
|
||||||
import {
|
|
||||||
convert as convertPandoc,
|
|
||||||
properties as propertiesPandoc,
|
|
||||||
} from "./pandoc";
|
|
||||||
import {
|
|
||||||
convert as convertresvg,
|
|
||||||
properties as propertiesresvg,
|
|
||||||
} from "./resvg";
|
|
||||||
import { convert as convertImage, properties as propertiesImage } from "./vips";
|
import { convert as convertImage, properties as propertiesImage } from "./vips";
|
||||||
import {
|
import { convert as convertxelatex, properties as propertiesxelatex } from "./xelatex";
|
||||||
convert as convertxelatex,
|
|
||||||
properties as propertiesxelatex,
|
|
||||||
} from "./xelatex";
|
|
||||||
|
|
||||||
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
|
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
|
||||||
|
|
||||||
|
|
@ -103,8 +83,7 @@ export async function mainConverter(
|
||||||
) {
|
) {
|
||||||
const fileType = normalizeFiletype(fileTypeOriginal);
|
const fileType = normalizeFiletype(fileTypeOriginal);
|
||||||
|
|
||||||
let converterFunc: ((filePath: string, fileType: string, convertTo: string, targetPath: string, options?: unknown) => unknown) | undefined;
|
let converterFunc: typeof properties["libjxl"]["converter"] | undefined;
|
||||||
// let converterName = converterName;
|
|
||||||
|
|
||||||
if (converterName) {
|
if (converterName) {
|
||||||
converterFunc = properties[converterName]?.converter;
|
converterFunc = properties[converterName]?.converter;
|
||||||
|
|
@ -137,7 +116,7 @@ export async function mainConverter(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await converterFunc(
|
const result = await converterFunc(
|
||||||
inputFilePath,
|
inputFilePath,
|
||||||
fileType,
|
fileType,
|
||||||
convertTo,
|
convertTo,
|
||||||
|
|
@ -147,7 +126,13 @@ export async function mainConverter(
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`Converted ${inputFilePath} from ${fileType} to ${convertTo} successfully using ${converterName}.`,
|
`Converted ${inputFilePath} from ${fileType} to ${convertTo} successfully using ${converterName}.`,
|
||||||
|
result,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (typeof result === "string") {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
return "Done";
|
return "Done";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|
@ -279,4 +264,4 @@ export const getAllInputs = (converter: string) => {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // print the number of unique Inputs and Outputs
|
// // print the number of unique Inputs and Outputs
|
||||||
// console.log(`Unique Formats: ${uniqueFormats.size}`);
|
// console.log(`Unique Formats: ${uniqueFormats.size}`);
|
||||||
|
|
@ -149,7 +149,7 @@ export function convert(
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
resolve("Done");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export function convert(
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
resolve("Done");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ export function convert(
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
resolve("Done");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export function convert(
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
resolve("Done");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue