Ver Fonte

Batch resize - Width and height #165

Ruben há 10 meses atrás
pai
commit
ce41ed0e4e

+ 7 - 0
src/PicView.Avalonia/ViewModels/ViewModelBase.cs

@@ -252,10 +252,17 @@ public class ViewModelBase : ReactiveObject
         Lossy = TranslationHelper.Translation.Lossy;
         Start = TranslationHelper.Translation.Start;
         Thumbnail = TranslationHelper.Translation.Thumbnail;
+        WidthAndHeight = TranslationHelper.Translation.WidthAndHeight;
     }
 
     #region Strings
     
+    public string? WidthAndHeight
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    }
+    
     public string? Thumbnail
     {
         get;

Diff do ficheiro suprimidas por serem muito extensas
+ 154 - 540
src/PicView.Avalonia/Views/BatchResizeView.axaml


+ 117 - 0
src/PicView.Avalonia/Views/BatchResizeView.axaml.cs

@@ -1,13 +1,130 @@
 using Avalonia.Controls;
+using PicView.Avalonia.Navigation;
+using PicView.Avalonia.ViewModels;
+using PicView.Core.Localization;
 
 namespace PicView.Avalonia.Views;
 public partial class BatchResizeView : UserControl
 {
+
+    private bool _isKeepingAspectRatio;
     public BatchResizeView()
     {
         InitializeComponent();
         Loaded += delegate
         {
+            if (DataContext is not MainViewModel vm)
+            {
+                return;
+            }
+
+            SourceFolderTextBox.TextChanged += delegate { CheckIfValidDirectory(SourceFolderTextBox.Text); };
+            SourceFolderTextBox.TextChanged += delegate
+            {
+                OutputFolderTextBox.Text = Path.Combine(SourceFolderTextBox.Text ?? string.Empty, TranslationHelper.Translation.BatchResize);
+            };
+
+            LinkChainButton.Click += delegate
+            {
+                if (_isKeepingAspectRatio)
+                {
+                    _isKeepingAspectRatio = false;
+                    LinkChainImage.IsVisible = true;
+                    UnlinkChainImage.IsVisible = false;
+                }
+                else
+                {
+                    _isKeepingAspectRatio = true;
+                    LinkChainImage.IsVisible = false;
+                    UnlinkChainImage.IsVisible = true;
+                }
+            };
+            
+            if (!NavigationHelper.CanNavigate(vm))
+            {
+                return;
+            }
+            
+            SourceFolderTextBox.Text = vm.FileInfo?.DirectoryName ?? string.Empty;
+            
+            StartButton.Click += async (_, _) => await StartBatchResize();
+
         };
     }
+
+    private async Task StartBatchResize()
+    {
+        if (DataContext is not MainViewModel vm)
+        {
+            return;
+        }
+        var file = vm.FileInfo.FullName;
+        var ext = vm.FileInfo.Extension;
+        var destination = string.IsNullOrWhiteSpace(OutputFolderTextBox.Text) ? SourceFolderTextBox.Text : OutputFolderTextBox.Text;
+        uint width = 0, height = 0;
+        if (!NoConversion.IsSelected)
+        {
+            if (PngItem.IsSelected)
+            {
+                ext = ".png";
+                destination = Path.ChangeExtension(destination, ".png");
+            }
+            else if (JpgItem.IsSelected)
+            {
+                ext = ".jpg";
+                destination = Path.ChangeExtension(destination, ".jpg");
+            }
+            else if (WebpItem.IsSelected)
+            {
+                ext = ".webp";
+                destination = Path.ChangeExtension(destination, ".webp");
+            }
+            else if (AvifItem.IsSelected)
+            {
+                ext = ".avif";
+                destination = Path.ChangeExtension(destination, ".avif");
+            }
+            else if (HeicItem.IsSelected)
+            {
+                ext = ".heic";
+                destination = Path.ChangeExtension(destination, ".heic");
+            }
+            else if (JxlItem.IsSelected)
+            {
+                ext = ".jxl";
+                destination = Path.ChangeExtension(destination, ".jxl");
+            }
+        }
+
+        uint? quality = null;
+        if (QualitySlider.IsEnabled)
+        {
+            if (ext == ".jpg" || Path.GetExtension(destination) == ".jpg" || Path.GetExtension(destination) == ".jpeg")
+            {
+                quality = (uint)QualitySlider.Value;
+            }
+        }
+
+        // var success = await SaveImageFileHelper.SaveImageAsync(null,
+        //     file,
+        //     destination,
+        //     width,
+        //     height,
+        //     quality,
+        //     ext,
+        //     null,
+        //     _isKeepingAspectRatio).ConfigureAwait(false);
+    }
+
+    private void CheckIfValidDirectory(string path)
+    {
+        if (!Directory.Exists(path))
+        {
+            StartButton.IsEnabled = false;
+            return;
+        }
+
+        StartButton.IsEnabled = true;
+
+    }
 }

+ 1 - 0
src/PicView.Core/Config/Languages/da.json

@@ -372,6 +372,7 @@
   "WhiteBalance": "Hvidbalance",
   "WhiteFluorescent": "Hvid fluorescerende",
   "Width": "Bredde",
+  "WidthAndHeight": "Bredde og højde",
   "WindowManagement": "vinduesstyring",
   "WindowScaling": "Skalering af vindue",
   "Zoom": "Zoom",

+ 1 - 0
src/PicView.Core/Config/Languages/de.json

@@ -372,6 +372,7 @@
   "WhiteBalance": "Weißabgleich",
   "WhiteFluorescent": "Weiß fluoreszierend",
   "Width": "Breite",
+  "WidthAndHeight": "Breite und Höhe",
   "WindowManagement": "Fensterverwaltung",
   "WindowScaling": "Fensterskalierung",
   "Zoom": "Zoom",

+ 1 - 0
src/PicView.Core/Config/Languages/en.json

@@ -373,6 +373,7 @@
   "WhiteBalance": "White balance",
   "WhiteFluorescent": "White fluorescent",
   "Width": "Width",
+  "WidthAndHeight": "Width and height",
   "WindowManagement": "Window management",
   "WindowScaling": "Window scaling",
   "Zoom": "Zoom",

+ 1 - 0
src/PicView.Core/Config/Languages/es.json

@@ -371,6 +371,7 @@
   "WhiteBalance": "Balance de blancos",
   "WhiteFluorescent": "Fluorescente blanco",
   "Width": "Ancho",
+  "WidthAndHeight": "Ancho y alto",
   "WindowManagement": "Gestión de ventana",
   "WindowScaling": "Escalado de ventana",
   "Zoom": "Zoom",

+ 1 - 0
src/PicView.Core/Config/Languages/fr.json

@@ -372,6 +372,7 @@
   "WhiteBalance": "Balance des blancs",
   "WhiteFluorescent": "Fluorescent blanc",
   "Width": "Largeur",
+  "WidthAndHeight": "Largeur et hauteur",
   "WindowManagement": "Gestion des fenêtres",
   "WindowScaling": "Mise à l'échelle de la fenêtre",
   "Zoom": "Zoomer",

+ 1 - 0
src/PicView.Core/Config/Languages/it.json

@@ -372,6 +372,7 @@
   "WhiteBalance": "Bilanciamento del bianco",
   "WhiteFluorescent": "Fluorescente bianco",
   "Width": "Larghezza",
+  "WidthAndHeight": "Larghezza e altezza",
   "WindowManagement": "Gestione delle finestre",
   "WindowScaling": "Ridimensionamento della finestra",
   "Zoom": "Zoom",

+ 1 - 0
src/PicView.Core/Config/Languages/ko.json

@@ -373,6 +373,7 @@
   "WhiteBalance": "화이트 밸런스",
   "WhiteFluorescent": "백색 형광등",
   "Width": "너비",
+  "WidthAndHeight": "너비와 높이",
   "WindowManagement": "창 관리",
   "WindowScaling": "창 비율",
   "Zoom": "확대/축소",

+ 1 - 0
src/PicView.Core/Config/Languages/pl.json

@@ -372,6 +372,7 @@
   "WhiteBalance": "Balans bieli",
   "WhiteFluorescent": "Biały - świetlówka",
   "Width": "Szerokość",
+  "WidthAndHeight": "Szerokość i wysokość",
   "WindowManagement": "Zarządzanie oknem",
   "WindowScaling": "Skalowanie okna",
   "Zoom": "Zoom",

+ 1 - 0
src/PicView.Core/Config/Languages/pt-br.json

@@ -373,6 +373,7 @@
   "WhiteBalance": "Equilíbrio do branco",
   "WhiteFluorescent": "Branco fluorescente",
   "Width": "Largura",
+  "WidthAndHeight": "Largura e altura",
   "WindowManagement": "Gerenciamento de janelas",
   "WindowScaling": "Dimensionamento da janela",
   "Zoom": "Zoom",

+ 1 - 0
src/PicView.Core/Config/Languages/ro.json

@@ -371,6 +371,7 @@
   "WhiteBalance": "Balans de alb",
   "WhiteFluorescent": "Fluorescent alb",
   "Width": "Lățime",
+  "WidthAndHeight": "Lățime și înălțime",
   "WindowManagement": "Gestionarea ferestrei",
   "WindowScaling": "Scalare fereastră",
   "Zoom": "Transfocare",

+ 1 - 0
src/PicView.Core/Config/Languages/ru.json

@@ -372,6 +372,7 @@
   "WhiteBalance": "Баланс белого",
   "WhiteFluorescent": "Белый флуоресцентный",
   "Width": "Ширина",
+  "WidthAndHeight": "Ширина и высота",
   "WindowManagement": "Управление окнами",
   "WindowScaling": "Масштабирование окна",
   "Zoom": "Зуммирование",

+ 1 - 0
src/PicView.Core/Config/Languages/sv.json

@@ -374,6 +374,7 @@
   "WhiteBalance": "Vitbalans",
   "WhiteFluorescent": "Lysrör vitt",
   "Width": "Bredd",
+  "WidthAndHeight": "Bredd och höjd",
   "WindowManagement": "Fönsterhantering",
   "WindowScaling": "Fönsterskalning",
   "Zoom": "Zooma",

+ 1 - 0
src/PicView.Core/Config/Languages/zh-CN.json

@@ -372,6 +372,7 @@
   "WhiteBalance": "白平衡",
   "WhiteFluorescent": "白光荧光",
   "Width": "宽度",
+  "WidthAndHeight": "宽度和高度",
   "WindowManagement": "窗口管理",
   "WindowScaling": "窗口缩放",
   "Zoom": "缩放",

+ 1 - 0
src/PicView.Core/Config/Languages/zh-TW.json

@@ -375,6 +375,7 @@
   "WhiteBalance": "白平衡",
   "WhiteFluorescent": "白螢光",
   "Width": "寬度",
+  "WidthAndHeight": "寬度和高度",
   "WindowManagement": "視窗管理",
   "WindowScaling": "視窗縮放",
   "Zoom": "縮放",

+ 2 - 0
src/PicView.Core/Localization/LanguageModel.cs

@@ -391,4 +391,6 @@ public record LanguageModel
     public string? AdvanceBy100Images { get; set; }
     public string? GoBackBy10Images { get; set; }
     public string? GoBackBy100Images { get; set; }
+    
+    public string? WidthAndHeight { get; set; }
 }

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff