This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We are pretty much feature set. There are a few thigns that need to be kinked out, but image conversion is complete and I'm starting on video conversion next.
- Loading branch information
1 parent
75142f0
commit f98e5a4
Showing
23 changed files
with
348 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,131 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ImageMagick; | ||
using NReco.VideoConverter; | ||
|
||
namespace Mr_Squirrely_Converters.Class | ||
{ | ||
class Converter | ||
{ | ||
|
||
#region Video Converters | ||
internal static void ConvertWebM(List<string> files) { | ||
try { | ||
|
||
// Currently disabled | ||
//FFMpegConverter video = new FFMpegConverter(); | ||
//foreach (string file in files) { | ||
// string fileName = Path.GetFileNameWithoutExtension(file); | ||
// string fileLocation = Path.GetDirectoryName(file); | ||
// string fileType = Path.GetExtension(file); | ||
// video.ConvertMedia(file, $"{fileLocation}\\{fileName}.webm", Format.webm); | ||
//} | ||
|
||
} | ||
catch (Exception) { | ||
|
||
} | ||
} | ||
|
||
internal static void ConvertMP4(List<string> files) { | ||
|
||
} | ||
#endregion | ||
|
||
#region Image Converters | ||
//If alpha true = remove else = set | ||
internal static void ConvertWebP(List<string> files) { | ||
foreach (string file in files) { | ||
string fileName = Path.GetFileNameWithoutExtension(file); | ||
string fullName = Path.GetFileName(file); | ||
string fileLocation = Path.GetDirectoryName(file); | ||
string fullLocation = Path.GetFullPath(file); | ||
MagickImage image = new MagickImage(file); | ||
image.Settings.SetDefine(MagickFormat.WebP, "lossless", true); | ||
image.Settings.SetDefine(MagickFormat.WebP, "emulate-jpeg-size", false); | ||
image.Settings.SetDefine(MagickFormat.WebP, "-lossless", Options.WebPLossless); | ||
image.Settings.SetDefine(MagickFormat.WebP, "-emulate-jpeg-size", Options.WebPEmulateJPEG); | ||
image.Settings.SetDefine(MagickFormat.WebP, "-alpha", Options.GetWebPRemoveAlpha()); | ||
image.Settings.SetDefine(MagickFormat.WebP, "-quality", Options.WebPQuality.ToString()); | ||
image.Format = MagickFormat.WebP; | ||
image.Write($"{fileLocation}\\{fileName}.webp"); | ||
//I need help on this. There has to be a better way to do this?! | ||
foreach (NewFile newFile in Utils._Images) { | ||
int index = Utils._Images.IndexOf(newFile); | ||
if (Utils._Images[index].Location == fullLocation) { | ||
Utils._Images[index].Converted = "Converted"; | ||
} | ||
} | ||
Utils._MainPage.Dispatcher.Invoke(() => { Utils._MainPage.ImageFiles.Items.Refresh(); }, System.Windows.Threading.DispatcherPriority.Background); | ||
if (Options.CreateTemp) { | ||
if (!Directory.Exists($"{Utils._WorkingDir}\\image_temp")) Directory.CreateDirectory($"{Utils._WorkingDir}\\image_temp"); | ||
File.Copy(file, $"{Utils._WorkingDir}\\image_temp\\{fullName}"); | ||
} | ||
DeleteFile(file); | ||
} | ||
} | ||
|
||
internal static void ConvertJPEG(List<string> files) { | ||
foreach (string file in files) { | ||
string fileName = Path.GetFileNameWithoutExtension(file); | ||
string fullName = Path.GetFileName(file); | ||
string fileLocation = Path.GetDirectoryName(file); | ||
string fullLocation = Path.GetFullPath(file); | ||
MagickImage image = new MagickImage(file); | ||
image.Settings.SetDefine(MagickFormat.Jpeg, "-quality", Options.WebPQuality.ToString()); | ||
image.Format = MagickFormat.Jpeg; | ||
image.Write($"{fileLocation}\\{fileName}.Jpeg"); | ||
//I need help on this. There has to be a better way to do this?! | ||
foreach (NewFile newFile in Utils._Images) { | ||
int index = Utils._Images.IndexOf(newFile); | ||
if (Utils._Images[index].Location == fullLocation) { | ||
Utils._Images[index].Converted = "Converted"; | ||
} | ||
} | ||
Utils._MainPage.Dispatcher.Invoke(() => { Utils._MainPage.ImageFiles.Items.Refresh(); }, System.Windows.Threading.DispatcherPriority.Background); | ||
if (Options.CreateTemp) { | ||
if (!Directory.Exists($"{Utils._WorkingDir}\\image_temp")) Directory.CreateDirectory($"{Utils._WorkingDir}\\image_temp"); | ||
File.Copy(file, $"{Utils._WorkingDir}\\image_temp\\{fullName}"); | ||
} | ||
DeleteFile(file); | ||
} | ||
} | ||
|
||
internal static void ConvertPNG(List<string> files) { | ||
foreach (string file in files) { | ||
string fileName = Path.GetFileNameWithoutExtension(file); | ||
string fullName = Path.GetFileName(file); | ||
string fileLocation = Path.GetDirectoryName(file); | ||
string fullLocation = Path.GetFullPath(file); | ||
MagickImage image = new MagickImage(file); | ||
image.Settings.SetDefine(MagickFormat.Png, "-lossless", Options.WebPLossless); | ||
image.Settings.SetDefine(MagickFormat.Png, "-alpha", Options.GetWebPRemoveAlpha()); | ||
image.Settings.SetDefine(MagickFormat.Png, "-quality", Options.WebPQuality.ToString()); | ||
image.Format = MagickFormat.Png; | ||
image.Write($"{fileLocation}\\{fileName}.Png"); | ||
//I need help on this. There has to be a better way to do this?! | ||
foreach (NewFile newFile in Utils._Images) { | ||
int index = Utils._Images.IndexOf(newFile); | ||
if (Utils._Images[index].Location == fullLocation) { | ||
Utils._Images[index].Converted = "Converted"; | ||
} | ||
} | ||
Utils._MainPage.Dispatcher.Invoke(() => { Utils._MainPage.ImageFiles.Items.Refresh(); }, System.Windows.Threading.DispatcherPriority.Background); | ||
if (Options.CreateTemp) { | ||
if (!Directory.Exists($"{Utils._WorkingDir}\\image_temp")) Directory.CreateDirectory($"{Utils._WorkingDir}\\image_temp"); | ||
File.Copy(file, $"{Utils._WorkingDir}\\image_temp\\{fullName}"); | ||
} | ||
DeleteFile(file); | ||
} | ||
} | ||
#endregion | ||
|
||
private static void DeleteFile(string file) { | ||
if (Options.ImagesDelete) File.Delete(file); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Mr_Squirrely_Converters.Class { | ||
class Options { | ||
|
||
internal static bool CreateTemp { get { return Properties.Settings.Default.Create_Temp; } set { Properties.Settings.Default.Create_Temp = value; } } | ||
internal static string TempLocation { get { return Properties.Settings.Default.Temp_Location; } set { Properties.Settings.Default.Temp_Location = value; } } | ||
internal static bool ImagesDelete { get { return Properties.Settings.Default.Images_Delete; } set { Properties.Settings.Default.Images_Delete = value; } } | ||
internal static bool WebPLossless { get { return Properties.Settings.Default.WebP_Lossess; } set { Properties.Settings.Default.WebP_Lossess = value; } } | ||
internal static bool WebPEmulateJPEG { get { return Properties.Settings.Default.WebP_Emulate_JPEG; } set { Properties.Settings.Default.WebP_Emulate_JPEG = value; } } | ||
internal static double WebPQuality { get { return Properties.Settings.Default.WebP_Quality; } set { Properties.Settings.Default.WebP_Quality = value; } } | ||
internal static bool WebPRemoveAlpha { get { return Properties.Settings.Default.WebP_RemoveAlpha; } set { Properties.Settings.Default.WebP_RemoveAlpha = value; } } | ||
internal static double JPEGQuality { get { return Properties.Settings.Default.JPEG_Quality; } set { Properties.Settings.Default.JPEG_Quality = value; } } | ||
internal static bool PNGLossless { get { return Properties.Settings.Default.PNG_Lossess; } set { Properties.Settings.Default.PNG_Lossess = value; } } | ||
internal static double PNGQuality { get { return Properties.Settings.Default.PNG_Quality; } set { Properties.Settings.Default.PNG_Quality = value; } } | ||
internal static bool PNGRemoveAlpha { get { return Properties.Settings.Default.PNG_RemoveAlpha; } set { Properties.Settings.Default.PNG_RemoveAlpha = value; } } | ||
|
||
internal static void Save() => Properties.Settings.Default.Save(); | ||
|
||
internal static string GetWebPRemoveAlpha() { | ||
if (WebPRemoveAlpha) return "remove"; else return "set"; | ||
} | ||
|
||
internal static string GetPNGRemoveAlpha() { | ||
if (PNGRemoveAlpha) return "remove"; else return "set"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.