ResizeIfSmaller mode for more resize options

This commit is contained in:
wolfborg 2017-01-11 21:35:15 -05:00
parent 64ccd5459d
commit ec202fc838

View file

@ -37,8 +37,8 @@ public class Resize : ImageEffect
[DefaultValue(0), Description("Use height as 0 to automatically adjust height to maintain aspect ratio.")]
public int Height { get; set; }
[DefaultValue(false), Description("Only resize image if it is bigger than specified size.")]
public bool ResizeIfBigger { get; set; }
[DefaultValue(ResizeMode.ResizeAll)]
public ResizeMode Mode { get; set; }
public Resize()
{
@ -52,10 +52,8 @@ public override Image Apply(Image img)
int width = Width <= 0 ? (int)((float)Height / img.Height * img.Width) : Width;
int height = Height <= 0 ? (int)((float)Width / img.Width * img.Height) : Height;
if (ResizeIfBigger && img.Width <= width && img.Height <= height)
{
return img;
}
if (Mode == ResizeMode.ResizeIfBigger && img.Width <= width && img.Height <= height) return img;
if (Mode == ResizeMode.ResizeIfSmaller && img.Width >= width && img.Height >= height) return img;
return ImageHelpers.ResizeImage(img, width, height);
}