public void CropFilter_UseXYWidthHeight_CalculatedCorrectly() { FastBitmap bitmap = new FastBitmap("Filters\\Images\\Tulips.png", UriKind.Relative); CropFilter cropFilter = new CropFilter(); cropFilter.X = 30; cropFilter.Y = 30; cropFilter.Width = 200; cropFilter.Height = 200; cropFilter.ApplyFilter(bitmap); Assert.AreEqual(200, bitmap.Width); Assert.AreEqual(200, bitmap.Height); bitmap.Save("TulipsCropped200x200.png"); FastBitmap expectedBitmap = new FastBitmap("Filters\\Images\\TulipsCropped200x200.png", UriKind.Relative); FastBitmapTestUtility.AssertEqual(expectedBitmap, bitmap); }
public string GetUrl(int width, int height, bool fill, DynamicImageFormat format, bool isResize) { //first construct the crop var imageSource = new ZeusImageSource(); imageSource.ContentID = this.ID; if (this.Data == null) return ""; // generate resized image url // set image format var dynamicImage = new SoundInTheory.DynamicImage.Composition(); dynamicImage.ImageFormat = format; // create image layer wit ha source var imageLayer = new ImageLayer(); imageLayer.Source = imageSource; // add filters if (!(TopLeftXVal == 0 && TopLeftYVal == 0 && CropWidth == 0 && CropHeight == 0)) { var cropFilter = new CropFilter { Enabled = true, X = this.TopLeftXVal, Y = this.TopLeftYVal, Width = this.CropWidth, Height = this.CropHeight }; if (!isResize) imageLayer.Filters.Add(cropFilter); } if (width > 0 && height > 0) { var resizeFilter = new ResizeFilter { Mode = isResize ? ResizeMode.Uniform : ResizeMode.UniformFill, Width = SoundInTheory.DynamicImage.Unit.Pixel(width), Height = SoundInTheory.DynamicImage.Unit.Pixel(height) }; imageLayer.Filters.Add(resizeFilter); } else if (width > 0) { var resizeFilter = new ResizeFilter { Mode = ResizeMode.UseWidth, Width = SoundInTheory.DynamicImage.Unit.Pixel(width) }; imageLayer.Filters.Add(resizeFilter); } else if (height > 0) { var resizeFilter = new ResizeFilter { Mode = ResizeMode.UseHeight, Height = SoundInTheory.DynamicImage.Unit.Pixel(height) }; imageLayer.Filters.Add(resizeFilter); } // add the layer dynamicImage.Layers.Add(imageLayer); // generate url return ImageUrlGenerator.GetImageUrl(dynamicImage); }