Skip to content

Commit

Permalink
Fixed percentage scale problems, added forced overwrite to PNG conver…
Browse files Browse the repository at this point in the history
…sion

TODO: Add for other formats as well?
  • Loading branch information
N00MKRAD committed Oct 10, 2020
1 parent 3adb3b4 commit edcaec6
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 2 deletions.
Binary file modified .vs/MagickUtils/v16/.suo
Binary file not shown.
2 changes: 2 additions & 0 deletions MagickUtils/ConvertUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public static void ConvertToPng(string path, int q = 50, bool delSource = false)
img.Quality = q;
string outPath = Path.ChangeExtension(path, null) + ".png";
PreProcessing(path);
if (path == outPath)
File.Delete(path);
img.Write(outPath);
PostProcessing(img, path, outPath, delSource);
}
Expand Down
3 changes: 2 additions & 1 deletion MagickUtils/ScaleUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Data.SqlClient;
using System.IO;
using ImageMagick;

Expand Down Expand Up @@ -108,7 +109,7 @@ public static void Scale (string path, float minScale, float maxScale, int randF
if(currMode == SM.Percentage)
{
Program.Print("-> Scaling to " + targetScale + "% with filter " + filter + "...");
MagickGeometry geom = new MagickGeometry(img.Width * targetScale / 100f + "x");
MagickGeometry geom = new MagickGeometry(Math.Round(img.Width * targetScale / 100f) + "x" + Math.Round(img.Height * targetScale));
img.Resize(geom);
}
PreProcessing(path);
Expand Down
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static int GetDefaultQuality (MagickImage img)
if(img.Format == MagickFormat.Jpg || img.Format == MagickFormat.Jpeg)
return 95;
if(img.Format == MagickFormat.Png)
return 30;
return Config.GetInt("pngQ");
if(img.Format == MagickFormat.WebP)
return 93;
return 99;
Expand Down
Binary file modified bin/x64/Debug/MagickUtils.exe
Binary file not shown.
Binary file modified bin/x64/Debug/MagickUtils.pdb
Binary file not shown.
Binary file modified obj/x64/Debug/MagickUtils.exe
Binary file not shown.
Binary file modified obj/x64/Debug/MagickUtils.pdb
Binary file not shown.

0 comments on commit edcaec6

Please sign in to comment.