Exemple #1
0
    static int Main(string[] args)
    {
        if (args.Length is < 1 or > 2)
        {
            Console.Error.WriteLine("Usage: webp-to-jpeg <input> [output]");
            return(1);
        }

        try
        {
            var inputFileName  = args[0];
            var outputFileName = args.Length > 1
                ? args[1]
                : Path.ChangeExtension(inputFileName, ".jpg");

            WebPExecuteDownloader.Download();

            var builder = new WebPDecoderBuilder();
            var decoder = builder.Build();

            using var output = File.Create(outputFileName);
            using var input  = File.OpenRead(inputFileName);
            decoder.Decode(input, output);
        }
        catch (Exception exception)
        {
            Console.Error.WriteLine($"Exception: {exception.Message}");
            return(1);
        }

        return(0);
    }
Exemple #2
0
        public void Case1()
        {
            var builder = new WebPDecoderBuilder();

            var encoder = builder
                          .Flip()
                          .Build();

            var output = new MemoryStream();

            using (var inputFile = File.Open("Samples/openCC.webp", FileMode.Open)) {
                encoder.Decode(inputFile, output);
            }

            Assert.NotEqual(0, output.Length);
        }
Exemple #3
0
        public void Case2()
        {
            var builder = new WebPDecoderBuilder();

            var encoder = builder
                          .Flip()
                          .Build();

            if (!Directory.Exists("Output"))
            {
                Directory.CreateDirectory("Output");
            }

            using (var outputFile = File.Open("Output/openCC-Flip.png", FileMode.Create))
                using (var inputFile = File.Open("Samples/openCC.webp", FileMode.Open)) {
                    encoder.Decode(inputFile, outputFile);
                }
        }
Exemple #4
0
        public void Case5()
        {
            var builder = new WebPDecoderBuilder();

            var encoder = builder
                          .Crop(0, 0, 50, 50)
                          .ExportFormat(ExportFormats.BMP)
                          .Build();

            if (!Directory.Exists("Output"))
            {
                Directory.CreateDirectory("Output");
            }

            using (var outputFile = File.Open("Output/openCC.bmp", FileMode.Create))
                using (var inputFile = File.Open("Samples/openCC.webp", FileMode.Open)) {
                    encoder.Decode(inputFile, outputFile);
                }
        }