Implemented gif exportation and added some style (again)

This commit is contained in:
Laurent
2026-02-17 18:20:53 +01:00
parent b81d912cf4
commit 4a5bf8dfff
10 changed files with 268 additions and 101 deletions

View File

@@ -0,0 +1,18 @@
namespace GifResizer.Models;
public class Format
{
public Format(int width, int height)
{
Width = width;
Height = height;
Checked = true;
}
public int Width { get; private set; }
public int Height { get; private set; }
public bool Checked { get; set; }
public override string ToString() => $"{Width}x{Height}";
}

View File

@@ -1,6 +1,4 @@
using System.Diagnostics;
using System.IO;
using GifResizer.Service;
using System.IO;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
@@ -9,7 +7,7 @@ namespace GifResizer.Models;
public class Gif : IDisposable
{
private readonly FileInfo _file;
private readonly string _path;
private Image? _image;
public Gif(string path)
@@ -17,18 +15,19 @@ public class Gif : IDisposable
ArgumentNullException.ThrowIfNull(path);
if (path.Length == 0 || path.IsWhiteSpace() || !File.Exists(path))
throw new ArgumentException($"File '{path}' does not exist");
_file = new FileInfo(path);
_path = path;
}
public void Load()
{
_image = Image.Load(_file.FullName);
_image = Image.Load(_path);
}
public void Resize(int width, int height)
{
if(_image == null) throw new InvalidOperationException("Image hasn't been loaded yet");
if(width <= 0 || height <= 0) throw new InvalidOperationException("Please specify a valid width or height.");
if(width == _image.Width && height == _image.Height) return;
_image.Mutate(x => x.Resize(width, height));
}

View File

@@ -0,0 +1,29 @@
using System.IO;
using SixLabors.ImageSharp;
namespace GifResizer.Models;
public class GifData
{
public GifData(string path)
{
Load(path);
}
private void Load(string path)
{
ArgumentNullException.ThrowIfNull(path);
if (path.Length == 0 || path.IsWhiteSpace() || !File.Exists(path))
throw new ArgumentException($"File '{path}' does not exist");
using Image image = Image.Load(path);
Path = path;
Width = image.Width;
Height = image.Height;
}
public string Path { get; private set; }
public int Width { get; private set; }
public int Height { get; private set; }
}