import { BuildBaseFileInputOutputModel, IMAGE_MAGICK_INPUT_FORMAT, IMAGE_MAGICK_OUTPUT_FORMAT, INKSCAPE_EXPORT_FORMAT, } from '../shared/type/index.js';
import { buildCommandToConvertAIToSVGWithInkscape, buildCommandToProcessImage, } from '../shared/index.js';
import { buildUseConvert, transform_input_output_file_array, } from './base.js';
import { handleCommand, } from './command.js';
// https://unix.stackexchange.com/questions/189364/script-to-determine-if-apparent-image-files-are-real-image-files/189367#189367
// export async function convertSVGToPNG({ inputPath, outputPath }) {
//   const dir = path.dirname(outputPath)
//   fs.mkdir(dir, { recursive: true })
//   const svgexport = require('svgexport')
//   const opts = {
//     input: inputPath,
//     output: outputPath,
//   }
//   svgexport.render(opts)
// }
// export async function removeEXIFData({ inputPath }) {
//   const data = fs.readFileSync(inputPath).toString('binary')
//   const piexif = require('piexifjs')
//   const newData = piexif.remove(data)
//   fs.writeFileSync(inputPath, newData, 'binary')
// }
// export async function readImageDimensions({ inputPath }) {
//   const probe = require('probe-image-size')
//   const data = fs.readFileSync(inputPath)
//   const meta = probe.sync(data)
//   return {
//     width: meta.width,
//     height: meta.height,
//   }
// }
// optimize animated gif:
// gifsicle -O3 --colors 256 --lossy=30 -o output.gif input.gif
// pix_fmt rgb24
// https://exiv2.org/tags.html
const IOImageMagick = BuildBaseFileInputOutputModel.superRefine(transform_input_output_file_array(IMAGE_MAGICK_INPUT_FORMAT, IMAGE_MAGICK_OUTPUT_FORMAT));
export const useConvertImageWithImageMagick = buildUseConvert(IMAGE_MAGICK_INPUT_FORMAT, IMAGE_MAGICK_OUTPUT_FORMAT, 'image_magick');
export async function convertImageWithImageMagick(source) {
    const input = IOImageMagick.parse(source);
    const list = buildCommandToProcessImage(input);
    for (const cmd of list) {
        await handleCommand(cmd);
    }
    return input.output.file.path;
}
const IOInkscape = BuildBaseFileInputOutputModel.superRefine(transform_input_output_file_array(['ai'], INKSCAPE_EXPORT_FORMAT));
export const useConvertImageWithInkscape = buildUseConvert(['ai'], INKSCAPE_EXPORT_FORMAT, 'inkscape');
export async function convertImageWithInkscape(source) {
    const input = IOInkscape.parse(source);
    const list = await buildCommandToConvertAIToSVGWithInkscape(input);
    for (const cmd of list) {
        await handleCommand(cmd);
    }
}
//# sourceMappingURL=image.js.map