From 77d33e4c8fda1bd216ca769c15467405d093cd10 Mon Sep 17 00:00:00 2001
From: Laurent <2-naaturel@users.noreply.gitlab.example.com>
Date: Tue, 17 Feb 2026 00:05:24 +0100
Subject: [PATCH] Implemented core logic
---
GifResizer/App.xaml.cs | 3 +-
GifResizer/GifResizer.csproj | 4 +++
GifResizer/Models/Gif.cs | 48 ++++++++++++++++++++++++--
GifResizer/Service/ResizeService.cs | 18 ++++++++--
GifResizer/ViewModels/MainViewModel.cs | 12 +++++--
GifResizer/Views/MainWindow.xaml | 6 ++++
GifResizer/Views/MainWindow.xaml.cs | 34 ++++++++++++++----
7 files changed, 111 insertions(+), 14 deletions(-)
diff --git a/GifResizer/App.xaml.cs b/GifResizer/App.xaml.cs
index 99dfa38..024f10c 100644
--- a/GifResizer/App.xaml.cs
+++ b/GifResizer/App.xaml.cs
@@ -1,6 +1,7 @@
using System.Configuration;
using System.Data;
using System.Windows;
+using GifResizer.Service;
using GifResizer.ViewModels;
using GifResizer.Views;
@@ -15,7 +16,7 @@ public partial class App : Application
{
base.OnStartup(e);
- var viewModel = new MainViewModel();
+ var viewModel = new MainViewModel(new ResizeService());
var mainWindow = new MainWindow(viewModel);
mainWindow.Show();
diff --git a/GifResizer/GifResizer.csproj b/GifResizer/GifResizer.csproj
index 50aaf7b..805bf3c 100644
--- a/GifResizer/GifResizer.csproj
+++ b/GifResizer/GifResizer.csproj
@@ -8,6 +8,10 @@
true
+
+
+
+
diff --git a/GifResizer/Models/Gif.cs b/GifResizer/Models/Gif.cs
index b468d18..cf67b93 100644
--- a/GifResizer/Models/Gif.cs
+++ b/GifResizer/Models/Gif.cs
@@ -1,6 +1,50 @@
-namespace GifResizer.Models;
+using System.Diagnostics;
+using System.IO;
+using GifResizer.Service;
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.Processing;
-public class Gif
+namespace GifResizer.Models;
+
+public class Gif : IDisposable
{
+
+ private readonly FileInfo _file;
+ private Image? _image;
+ public Gif(string path)
+ {
+ ArgumentNullException.ThrowIfNull(path);
+ if (path.Length == 0 || path.IsWhiteSpace() || !File.Exists(path))
+ throw new ArgumentException($"File '{path}' does not exist");
+
+ _file = new FileInfo(path);
+ }
+
+ public void Load()
+ {
+ _image = Image.Load(_file.FullName);
+ }
+
+ public void Resize(int width, int height)
+ {
+ if(_image == null) throw new InvalidOperationException("Image hasn't been loaded yet");
+ _image.Mutate(x => x.Resize(width, height));
+ }
+
+ public void Save(string outputPath)
+ {
+ if(_image == null) throw new InvalidOperationException("Image hasn't been loaded yet");
+ var directory = Path.GetDirectoryName(outputPath);
+ if (!string.IsNullOrEmpty(directory))
+ {
+ Directory.CreateDirectory(directory);
+ }
+ _image.Save(Path.Combine(outputPath));
+ }
+
+ public void Dispose()
+ {
+ _image?.Dispose();
+ }
}
\ No newline at end of file
diff --git a/GifResizer/Service/ResizeService.cs b/GifResizer/Service/ResizeService.cs
index 3cde8c4..0a7021a 100644
--- a/GifResizer/Service/ResizeService.cs
+++ b/GifResizer/Service/ResizeService.cs
@@ -1,6 +1,20 @@
-namespace GifResizer.Service;
+using GifResizer.Models;
+
+namespace GifResizer.Service;
public class ResizeService
{
-
+
+ public ResizeService()
+ {
+
+ }
+
+ public void ResizeGif(string filePath, int width, int height)
+ {
+ using Gif gif = new Gif(filePath);
+ gif.Load();
+ gif.Resize(width, height);
+ gif.Save("D:/test-output.gif");
+ }
}
\ No newline at end of file
diff --git a/GifResizer/ViewModels/MainViewModel.cs b/GifResizer/ViewModels/MainViewModel.cs
index 777f973..fb4b95b 100644
--- a/GifResizer/ViewModels/MainViewModel.cs
+++ b/GifResizer/ViewModels/MainViewModel.cs
@@ -1,17 +1,20 @@
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
+using GifResizer.Models;
+using GifResizer.Service;
namespace GifResizer.ViewModels;
public class MainViewModel : INotifyPropertyChanged
{
-
+ private readonly ResizeService _resizeService;
public event PropertyChangedEventHandler? PropertyChanged;
- public MainViewModel()
+ public MainViewModel(ResizeService service)
{
+ _resizeService = service;
FilePath = Directory.GetCurrentDirectory();
}
@@ -21,6 +24,11 @@ public class MainViewModel : INotifyPropertyChanged
get;
set => SetField(ref field, value);
}
+
+ public void ResizeGif(int width, int height)
+ {
+ _resizeService.ResizeGif(FilePath, width, height);
+ }
private bool SetField(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
diff --git a/GifResizer/Views/MainWindow.xaml b/GifResizer/Views/MainWindow.xaml
index 93cc274..b9463ae 100644
--- a/GifResizer/Views/MainWindow.xaml
+++ b/GifResizer/Views/MainWindow.xaml
@@ -45,6 +45,12 @@
+
+
+
+
+
+