public async Task ExactBoth(int sourceWidth, int sourceHeight, int desiredWidth, int desiredHeight)
        {
            var resizer     = _serviceProvider.GetRequiredService <IImageResizer>();
            var source      = DebugImageData.CreateSource(new DebugImageData(sourceWidth, sourceHeight, ImageTypes.Jpeg));
            var destination = DebugImageData.CreateDestination();
            await resizer.ResizeAsync(source, destination, new ResizeOptions(resizeMode : "exact", width : desiredWidth, height : desiredHeight));

            Assert.NotNull(destination.Data);
            Assert.Equal(desiredWidth, destination.Data.Width);
            Assert.Equal(desiredHeight, destination.Data.Height);
            Assert.Equal(ImageTypes.Jpeg, destination.Data.ImageType);
        }
        public async Task Noop()
        {
            var resizer     = _serviceProvider.GetRequiredService <IImageResizer>();
            var source      = DebugImageData.CreateSource(new DebugImageData(400, 400, ImageTypes.Jpeg));
            var destination = DebugImageData.CreateDestination();
            await resizer.ResizeAsync(source, destination, new ResizeOptions());

            Assert.NotNull(destination.Data);
            Assert.Equal(400, destination.Data.Width);
            Assert.Equal(400, destination.Data.Height);
            Assert.Equal(ImageTypes.Jpeg, destination.Data.ImageType);
            await resizer.ResizeAsync(source, destination, new ResizeOptions(imageType : ImageTypes.Png));

            Assert.NotNull(destination.Data);
            Assert.Equal(400, destination.Data.Width);
            Assert.Equal(400, destination.Data.Height);
            Assert.Equal(ImageTypes.Png, destination.Data.ImageType);
        }
        public async Task Exact(int sourceWidth, int sourceHeight, int?desiredWidth, int?desiredHeight)
        {
            var resizer     = _serviceProvider.GetRequiredService <IImageResizer>();
            var source      = DebugImageData.CreateSource(new DebugImageData(sourceWidth, sourceHeight, ImageTypes.Jpeg));
            var destination = DebugImageData.CreateDestination();
            await resizer.ResizeAsync(source, destination, new ResizeOptions(resizeMode : "exact", width : desiredWidth, height : desiredHeight));

            Assert.NotNull(destination.Data);
            if (desiredWidth.HasValue)
            {
                Assert.Equal(desiredWidth.Value, destination.Data.Width);
                var h = (int)((double)desiredWidth.Value * sourceHeight / sourceWidth);
                Assert.Equal(h, destination.Data.Height);
            }
            if (desiredHeight.HasValue)
            {
                Assert.Equal(desiredHeight.Value, destination.Data.Height);
                var w = (int)((double)desiredHeight.Value * sourceWidth / sourceHeight);
                Assert.Equal(w, destination.Data.Width);
            }
            Assert.Equal(ImageTypes.Jpeg, destination.Data.ImageType);
        }
 public IStreamConsumer CreateConsumer(ContentInfo contentInfo)
 => StreamConsumer.Create(DeserializeAsync).Bind(data => Data = data);
 public DebugImageSource(DebugImageData data) => _data = data ?? throw new ArgumentNullException(nameof(data));
Example #6
0
        public async ValueTask <IImage> FromStreamAsync(Stream source, CancellationToken cancellationToken = default)
        {
            var data = await DebugImageData.DeserializeAsync(source, cancellationToken);

            return(new DebugImage(new Size(data.Width, data.Height), data.ImageType));
        }