Example #1
0
        private async Task CreateMini(string root, string name)
        {
            await using var image        = new FileStream(Path.Combine(root, name), FileMode.Open);
            await using var resizedImage = await _imageResizer.Reduce(image, Threshold, default);

            var miniFilename = Path.Combine(root, _imagesSettings.MiniPrefix + name);

            await using var mimiImage = File.Create(miniFilename);
            await resizedImage.CopyToAsync(mimiImage);
        }
Example #2
0
        private async Task HandleMini(string type, string folder, string name, FileStream image,
                                      CancellationToken cancellationToken)
        {
            if (type != "Certificates" && type != "Products")
            {
                return;
            }

            var filename  = Path.GetFileNameWithoutExtension(name);
            var extension = Path.GetExtension(name);

            var miniFilename = _imagesSettings.MiniPrefix + filename + extension;
            var miniFullname = Path.Combine(folder, miniFilename);

            var miniImage = await _imageResizer.Reduce(image, 512, cancellationToken);

            await using var miniFile = File.Create(miniFullname, (int)miniImage.Length, FileOptions.Asynchronous);
            miniImage.Position       = 0;
            await miniImage.CopyToAsync(miniFile, cancellationToken);
        }