mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Merge pull request #2196 from wolfborg/master
ResizeIfSmaller Option for Resizing
This commit is contained in:
commit
c9116cc3db
2 changed files with 14 additions and 6 deletions
|
@ -167,4 +167,14 @@ public enum HotkeyStatus
|
||||||
Failed,
|
Failed,
|
||||||
NotConfigured
|
NotConfigured
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ResizeMode
|
||||||
|
{
|
||||||
|
[Description("Resizes all images to the specified size.")]
|
||||||
|
ResizeAll,
|
||||||
|
[Description("Only resize image if it is bigger than specified size.")]
|
||||||
|
ResizeIfBigger,
|
||||||
|
[Description("Only resize image if it is smaller than specified size.")]
|
||||||
|
ResizeIfSmaller
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -37,8 +37,8 @@ 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.")]
|
[DefaultValue(ResizeMode.ResizeAll)]
|
||||||
public bool ResizeIfBigger { get; set; }
|
public ResizeMode Mode { get; set; }
|
||||||
|
|
||||||
public Resize()
|
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 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)
|
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 img;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ImageHelpers.ResizeImage(img, width, height);
|
return ImageHelpers.ResizeImage(img, width, height);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue