mirror of
https://github.com/Geckon01/Watermark.Net.git
synced 2026-06-17 00:27:47 +00:00
Class names and namespaces improvements
This commit is contained in:
@@ -18,4 +18,8 @@
|
||||
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="src\WatermarkNet.Types\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -5,7 +5,6 @@ using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Watermark.Net.src.WatermarkNet.Enums;
|
||||
using Watermark.Net.src.WatermarkNet.Models.Definitions;
|
||||
using Watermark.Net.src.WatermarkNet.Types;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
@@ -36,17 +35,17 @@ namespace Watermark.Net.src.WatermarkNet.Core
|
||||
/// <param name="directory">Source directory containing images to process.</param>
|
||||
/// <param name="watermark">Watermark configuration.</param>
|
||||
/// <returns>List of processed images with watermark information.</returns>
|
||||
public List<WmarkedImage> ProcessDirectory<T>(string directory, T watermark)
|
||||
public List<ResultImage> ProcessDirectory<T>(string directory, T watermark)
|
||||
where T : IWatermarkDefinition
|
||||
{
|
||||
List<WmarkedImage> processedImages = new List<WmarkedImage>();
|
||||
List<ResultImage> processedImages = new List<ResultImage>();
|
||||
foreach (var imageFile in Directory.GetFiles(directory))
|
||||
{
|
||||
//Do not process directories and hidden files
|
||||
if (File.GetAttributes(imageFile).HasFlag(FileAttributes.Directory) || File.GetAttributes(imageFile).HasFlag(FileAttributes.Hidden))
|
||||
continue;
|
||||
|
||||
WmarkedImage? resultedImage = null;
|
||||
ResultImage? resultedImage = null;
|
||||
if (typeof(T).IsAssignableTo(typeof(ImageWatermark)))
|
||||
{
|
||||
var concreateWatermark = (ImageWatermark)Convert.ChangeType(watermark, typeof(ImageWatermark));
|
||||
@@ -71,13 +70,13 @@ namespace Watermark.Net.src.WatermarkNet.Core
|
||||
/// <param name="watermark">Image watermark configuration.</param>
|
||||
/// <returns>Processed image information or null on failure.</returns>
|
||||
/// <exception cref="FileNotFoundException">Thrown when source image or watermark image is missing.</exception>
|
||||
public WmarkedImage? ProcessImage(string imagePath, string outputDirectory, ImageWatermark watermark)
|
||||
public ResultImage? ProcessImage(string imagePath, string outputDirectory, ImageWatermark watermark)
|
||||
{
|
||||
if (!File.Exists(imagePath)) { throw new FileNotFoundException("Source file not found!", imagePath); }
|
||||
if (!File.Exists(watermark.ImagePath)) { throw new FileNotFoundException("Watermark file not found!", imagePath); }
|
||||
if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); }
|
||||
|
||||
WmarkedImage? resultedImage = null;
|
||||
ResultImage? resultedImage = null;
|
||||
using (var targetImage = Image.Load(imagePath))
|
||||
using (var watermarkImage = Image.Load(watermark.ImagePath))
|
||||
{
|
||||
@@ -87,7 +86,7 @@ namespace Watermark.Net.src.WatermarkNet.Core
|
||||
|
||||
using (var markedImage = targetImage.Clone(ctx => this.ApplyScalingWaterMarkImage(ctx, watermark, watermarkImage, targetImage)))
|
||||
{
|
||||
resultedImage = new WmarkedImage(markedImage, outputDirectory + Path.DirectorySeparatorChar + Path.GetFileName(imagePath));
|
||||
resultedImage = new ResultImage(markedImage, outputDirectory + Path.DirectorySeparatorChar + Path.GetFileName(imagePath));
|
||||
markedImage.Save(resultedImage.Path);
|
||||
}
|
||||
}
|
||||
@@ -102,17 +101,17 @@ namespace Watermark.Net.src.WatermarkNet.Core
|
||||
/// <param name="watermark">Text watermark configuration.</param>
|
||||
/// <returns>Processed image information or null on failure.</returns>
|
||||
/// <exception cref="FileNotFoundException">Thrown when source image is missing.</exception>
|
||||
public WmarkedImage? ProcessImage(string imagePath, string outputDirectory, TextWatermark watermark)
|
||||
public ResultImage? ProcessImage(string imagePath, string outputDirectory, TextWatermark watermark)
|
||||
{
|
||||
if(!File.Exists(imagePath)) { throw new FileNotFoundException("Source file not found!", imagePath); }
|
||||
if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); }
|
||||
|
||||
WmarkedImage? resultedImage = null;
|
||||
ResultImage? resultedImage = null;
|
||||
using (var targetImage = Image.Load(imagePath))
|
||||
{
|
||||
using (var markedImage = targetImage.Clone(ctx => this.ApplyScalingWaterMarkText(ctx, watermark)))
|
||||
{
|
||||
resultedImage = new WmarkedImage(markedImage, outputDirectory + Path.DirectorySeparatorChar + Path.GetFileName(imagePath));
|
||||
resultedImage = new ResultImage(markedImage, outputDirectory + Path.DirectorySeparatorChar + Path.GetFileName(imagePath));
|
||||
markedImage.Save(resultedImage.Path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using SixLabors.ImageSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Watermark.Net.src.WatermarkNet.Models.Definitions
|
||||
{
|
||||
public class ResultImage
|
||||
{
|
||||
public string Path { get; }
|
||||
public Image Image { get; }
|
||||
public ResultImage(Image image, string path)
|
||||
{
|
||||
this.Image = image;
|
||||
this.Path = path;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SixLabors.ImageSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Watermark.Net.src.WatermarkNet.Models.Definitions
|
||||
{
|
||||
public class SourceImage
|
||||
{
|
||||
public Image Image { get; set; }
|
||||
public String Path { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
namespace Watermark.Net.src.WatermarkNet.Types
|
||||
{
|
||||
internal class SourceImage
|
||||
{
|
||||
private string _path;
|
||||
private Image _image;
|
||||
|
||||
public Image Image => _image;
|
||||
public String Path => _path;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
namespace Watermark.Net.src.WatermarkNet.Types
|
||||
{
|
||||
public class WmarkedImage
|
||||
{
|
||||
public string Path { get; }
|
||||
public Image Image { get; }
|
||||
public WmarkedImage(Image image, string path)
|
||||
{
|
||||
this.Image = image;
|
||||
this.Path= path;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user