-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertFiles.cs
More file actions
30 lines (25 loc) · 1.21 KB
/
Copy pathConvertFiles.cs
File metadata and controls
30 lines (25 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Api2Convert;
namespace Api2Convert.Examples;
// Guide: Convert Files — browse the conversions catalog, then convert a JPG to PNG.
// Run: API2CONVERT_API_KEY=your-key dotnet run --project examples/Examples -- convert-files
internal static class ConvertFiles
{
public static async Task RunAsync()
{
using Api2ConvertClient client = Shared.NewClient();
// The full catalog of supported conversions.
IReadOnlyList<IReadOnlyDictionary<string, object?>> all = await client.Conversions.ListAsync();
Console.WriteLine($"Catalog entries: {all.Count}");
// Narrowed to conversions whose target is PNG.
IReadOnlyList<IReadOnlyDictionary<string, object?>> toPng =
await client.Conversions.ListAsync(target: "png");
Console.WriteLine($"Conversions targeting png: {toPng.Count}");
// Now run one of them: JPG -> PNG.
ConversionResult result = await client.ConvertAsync(Shared.Jpg, "png");
string path = await result.SaveAsync(Shared.OutputDir("convert-files") + System.IO.Path.DirectorySeparatorChar);
Console.WriteLine($"Saved: {path}");
}
}