static bool WidthValid(MagickImage img, Op op, int minPixels) { if (op == Op.IsSmaller && img.Width >= minPixels) { return(true); // Not smaller. Return (do not delete). } if (op == Op.IsBigger && img.Width <= minPixels) { return(true); // Not bigger. Return (do not delete). } if (op == Op.Is && img.Width != minPixels) { return(true); // Not equal. Return (do not delete). } if (op == Op.IsNot && img.Width == minPixels) { return(true); // Equal. Return (do not delete). } if (op == Op.Divisible && (img.Width % minPixels != 0)) { return(true); // Equal. Return (do not delete). } if (op == Op.NotDivisible && (img.Width % minPixels == 0)) { return(true); // Equal. Return (do not delete). } return(false); }
public static void DeleteSmallImages(string path, SM mode, Op op, int minPixels) { MagickImage img = IOUtils.ReadImage(path, false); if (img == null) { return; } bool heightLonger = img.Height > img.Width; bool widthLonger = img.Width > img.Height; bool square = (img.Height == img.Width); if (mode == SM.EitherSide) { if (HeightValid(img, op, minPixels) && WidthValid(img, op, minPixels)) { return; } } else if (mode == SM.BothSides) { if (HeightValid(img, op, minPixels) || WidthValid(img, op, minPixels)) { return; } } if (square || mode == SM.Height || (mode == SM.LongerSide && heightLonger) || (mode == SM.ShorterSide && widthLonger)) { if (HeightValid(img, op, minPixels)) { return; } } else if (mode == SM.Width || (mode == SM.LongerSide && widthLonger) || (mode == SM.ShorterSide && heightLonger)) { if (WidthValid(img, op, minPixels)) { return; } } string fname = Path.GetFileName(path); Logger.Log("-> Deleted " + fname + " (" + img.Width + "x" + img.Height + ")"); File.Delete(img.FileName); }