예제 #1
0
        public void NoResize()
        {
            ResetHostingDir();

            using var stream = _imageFile.OpenStream();

            var key = _host.Add(stream, new ImageOptions());

            Assert.ThrowsException <ArgumentException>(() => _host.AddSize(key, "original", new ImageOptions()));

            _host.AddSize(key, "enlarged1", new ImageOptions()
            {
                ImageEditor = ImageEditors.MaxSize(new Size(2000, 2000), Color.White),
            });

            _host.AddSize(key, "enlarged2", new ImageOptions()
            {
                ImageEditor = ImageEditors.Crop(new Size(2048, 1536), Color.White),
            });

            using (var image = Image.FromFile(_host.GetAbsoluteImagePath(key).PathExport)) {
                image.Width.ShouldBe(1024);
                image.Height.ShouldBe(768);
            }

            using (var enlarged1 = Image.FromFile(_host.GetAbsoluteImagePath(key, "enlarged1").PathExport)) {
                enlarged1.Width.ShouldBe(1024);
                enlarged1.Height.ShouldBe(768);
            }

            using (var enlarged2 = Image.FromFile(_host.GetAbsoluteImagePath(key, "enlarged2").PathExport)) {
                enlarged2.Width.ShouldBe(1024);
                enlarged2.Height.ShouldBe(768);
            }
        }
예제 #2
0
        public void Crop()
        {
            ResetHostingDir();

            using var stream = _imageFile.OpenStream();

            var key = _host.Add(stream, new ImageOptions()
            {
                ImageEditor = ImageEditors.Crop(new Size(500, 500), Color.White),
            });

            _host.AddSize(key, "thumbnail", new ImageOptions()
            {
                ImageEditor = ImageEditors.Crop(new Size(150, 150), Color.White),
            });

            using (var image = Image.FromFile(_host.GetAbsoluteImagePath(key).PathExport)) {
                image.Width.ShouldBe(500);
                image.Height.ShouldBe(500);
            }

            using (var thumbnail = Image.FromFile(_host.GetAbsoluteImagePath(key, "thumbnail").PathExport)) {
                thumbnail.Width.ShouldBe(150);
                thumbnail.Height.ShouldBe(150);
            }
        }