fixed #403: Optional resize if bigger setting

This commit is contained in:
Jaex 2014-12-12 11:49:25 +02:00
parent 3e4e3c27bf
commit d2af9182b1

View file

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