Merge pull request #165 from C4illin/fix/#157/resize-when-converting-to-ico

This commit is contained in:
Emrik Östling
2024-10-06 00:46:22 +02:00
committed by GitHub
9 changed files with 36 additions and 43 deletions

View File

@@ -137,7 +137,7 @@ export async function convert(
console.error(`stderr: ${stderr}`);
}
resolve("success");
resolve("Done");
});
});
}

View File

@@ -1,6 +1,5 @@
import { exec } from "node:child_process";
// This could be done dynamically by running `ffmpeg -formats` and parsing the output
export const properties = {
from: {
@@ -692,7 +691,16 @@ export async function convert(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: unknown,
): 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) => {
exec(command, (error, stdout, stderr) => {
@@ -708,7 +716,7 @@ export async function convert(
console.error(`stderr: ${stderr}`);
}
resolve("success");
resolve(message);
});
});
}
}

View File

@@ -332,7 +332,7 @@ export function convert(
console.error(`stderr: ${stderr}`);
}
resolve("success");
resolve("Done");
},
);
});

View File

@@ -65,7 +65,7 @@ export function convert(
console.error(`stderr: ${stderr}`);
}
resolve("success");
resolve("Done");
});
});
}

View File

@@ -1,33 +1,13 @@
import { normalizeFiletype } from "../helpers/normalizeFiletype";
import {
convert as convertassimp,
properties as propertiesassimp,
} from "./assimp";
import {
convert as convertFFmpeg,
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 convertassimp, properties as propertiesassimp } from "./assimp";
import { convert as convertFFmpeg, 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 convertxelatex,
properties as propertiesxelatex,
} from "./xelatex";
import { 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
@@ -103,8 +83,7 @@ export async function mainConverter(
) {
const fileType = normalizeFiletype(fileTypeOriginal);
let converterFunc: ((filePath: string, fileType: string, convertTo: string, targetPath: string, options?: unknown) => unknown) | undefined;
// let converterName = converterName;
let converterFunc: typeof properties["libjxl"]["converter"] | undefined;
if (converterName) {
converterFunc = properties[converterName]?.converter;
@@ -137,7 +116,7 @@ export async function mainConverter(
}
try {
await converterFunc(
const result = await converterFunc(
inputFilePath,
fileType,
convertTo,
@@ -147,7 +126,13 @@ export async function mainConverter(
console.log(
`Converted ${inputFilePath} from ${fileType} to ${convertTo} successfully using ${converterName}.`,
result,
);
if (typeof result === "string") {
return result;
}
return "Done";
} catch (error) {
console.error(
@@ -279,4 +264,4 @@ export const getAllInputs = (converter: string) => {
// }
// // print the number of unique Inputs and Outputs
// console.log(`Unique Formats: ${uniqueFormats.size}`);
// console.log(`Unique Formats: ${uniqueFormats.size}`);

View File

@@ -149,7 +149,7 @@ export function convert(
console.error(`stderr: ${stderr}`);
}
resolve("success");
resolve("Done");
},
);
});

View File

@@ -31,7 +31,7 @@ export function convert(
console.error(`stderr: ${stderr}`);
}
resolve("success");
resolve("Done");
});
});
}

View File

@@ -134,7 +134,7 @@ export function convert(
console.error(`stderr: ${stderr}`);
}
resolve("success");
resolve("Done");
},
);
});

View File

@@ -39,7 +39,7 @@ export function convert(
console.error(`stderr: ${stderr}`);
}
resolve("success");
resolve("Done");
},
);
});