Esempio n. 1
0
    static async Task CallPngquant(string tempPng, string png)
    {
        ProcessStartInfo pngquant = new()
        {
            FileName               = "pngquant.exe",
            UseShellExecute        = false,
            RedirectStandardOutput = true,
            RedirectStandardError  = true,
            CreateNoWindow         = true
        };

        pngquant.AppendArguments("--force", "--verbose", "--ordered", "--speed=1", "--skip-if-larger", "--quality=50-70", tempPng, "--output", png);

        EnvironmentHelpers.AppendToPath(pngquantPath);
        using var process = Process.Start(pngquant) !;
        await process.WaitForExitAsync();

        //skip-if-larger can result in 98 "not saved"
        if (process.ExitCode == 98)
        {
            File.Move(tempPng, png);
        }
        else
        {
            File.Delete(tempPng);
        }
    }
    static async Task Run(string fileName, params string[] arguments)
    {
        ProcessStartInfo startInfo = new(fileName)
        {
            CreateNoWindow         = true,
            RedirectStandardOutput = true,
            RedirectStandardError  = true,
            UseShellExecute        = false
        };

        startInfo.AppendArguments(arguments);

        EnvironmentHelpers.AppendToPath(ogr2ogrPath);
        using var process = Process.Start(startInfo) !;
        await process.WaitForExitAsync();

        if (process.ExitCode != 0)
        {
            var readToEnd = await process.StandardError.ReadToEndAsync();

            if (readToEnd.Contains("Error"))
            {
                throw new($"Failed to run: {arguments}. Output: {readToEnd}");
            }
        }
    }
}
Esempio n. 3
0
    static async Task CallGhostScript(string pdf, string tempPng)
    {
        ProcessStartInfo gswin64 = new()
        {
            FileName               = "gswin64c.exe",
            UseShellExecute        = false,
            RedirectStandardOutput = true,
            RedirectStandardError  = true,
            CreateNoWindow         = true
        };

        gswin64.AppendArguments("-dNoCancel", "-sDEVICE=png16m", "-dBATCH", "-r300", "-dNOPAUSE", "-dDownScaleFactor=2", "-q", $"-sOutputFile={tempPng}", pdf);

        EnvironmentHelpers.AppendToPath(ghostScriptPath);
        using var process = Process.Start(gswin64) !;
        await process.WaitForExitAsync();
    }
}