Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

feat(presets): a custom resize, free width and height with an aspect lock (#576)

choksi2212d157476f4fc2
diff --git a/src/Filee.App/Assets/i18n/ar.json b/src/Filee.App/Assets/i18n/ar.json
index 3de1151e..2e00eaf0 100644
--- a/src/Filee.App/Assets/i18n/ar.json
+++ b/src/Filee.App/Assets/i18n/ar.json
@@ -587,6 +587,7 @@
"presets.resize.Percent": "تغيير بنسبة مئوية",
"presets.resize.LongEdge": "تحديد الحد الأقصى للضلع الأطول",
"presets.resize.Width": "تعيين العرض",
+ "presets.resize.Custom": "تعيين العرض والارتفاع",
"presets.rotation": "التدوير",
"presets.rotation.None": "دون تدوير",
"presets.rotation.Right90": "90° لليمين",
@@ -599,6 +600,8 @@
"presets.percent": "النسبة المئوية",
"presets.long_edge": "الضلع الأطول (بكسل)",
"presets.width": "العرض (بكسل)",
+ "presets.height": "الارتفاع (بكسل)",
+ "presets.lock_aspect": "الحفاظ على نسبة الأبعاد",
"presets.dpi": "الدقة (DPI)",
"presets.dpi_keep": "الاحتفاظ بها",
"presets.keep_metadata": "الاحتفاظ بالبيانات الوصفية (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/de.json b/src/Filee.App/Assets/i18n/de.json
index fc742a82..3036246d 100644
--- a/src/Filee.App/Assets/i18n/de.json
+++ b/src/Filee.App/Assets/i18n/de.json
@@ -587,6 +587,7 @@
"presets.resize.Percent": "Prozentual skalieren",
"presets.resize.LongEdge": "Lange Kante begrenzen",
"presets.resize.Width": "Breite festlegen",
+ "presets.resize.Custom": "Breite und Höhe festlegen",
"presets.rotation": "Drehen",
"presets.rotation.None": "Nicht drehen",
"presets.rotation.Right90": "90° nach rechts",
@@ -599,6 +600,8 @@
"presets.percent": "Prozent",
"presets.long_edge": "Lange Kante (px)",
"presets.width": "Breite (px)",
+ "presets.height": "Höhe (px)",
+ "presets.lock_aspect": "Seitenverhältnis beibehalten",
"presets.dpi": "DPI",
"presets.dpi_keep": "Beibehalten",
"presets.keep_metadata": "Metadaten beibehalten (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index 75d0ee92..da881d0c 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "Scale by percent",
"presets.resize.LongEdge": "Limit the long edge",
"presets.resize.Width": "Set the width",
+ "presets.resize.Custom": "Set width and height",
"presets.rotation": "Rotate",
"presets.rotation.None": "Don't rotate",
"presets.rotation.Right90": "Right 90°",
@@ -614,6 +615,8 @@
"presets.percent": "Percent",
"presets.long_edge": "Long edge (px)",
"presets.width": "Width (px)",
+ "presets.height": "Height (px)",
+ "presets.lock_aspect": "Keep aspect ratio",
"presets.dpi": "DPI",
"presets.dpi_keep": "Keep",
"presets.keep_metadata": "Keep metadata (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.json
index c074a17f..290c90b5 100644
--- a/src/Filee.App/Assets/i18n/es.json
+++ b/src/Filee.App/Assets/i18n/es.json
@@ -587,6 +587,7 @@
"presets.resize.Percent": "Escalar por porcentaje",
"presets.resize.LongEdge": "Limitar el lado largo",
"presets.resize.Width": "Fijar el ancho",
+ "presets.resize.Custom": "Fijar el ancho y el alto",
"presets.rotation": "Rotar",
"presets.rotation.None": "No rotar",
"presets.rotation.Right90": "90° a la derecha",
@@ -599,6 +600,8 @@
"presets.percent": "Porcentaje",
"presets.long_edge": "Lado largo (px)",
"presets.width": "Ancho (px)",
+ "presets.height": "Alto (px)",
+ "presets.lock_aspect": "Mantener la proporción",
"presets.dpi": "DPI",
"presets.dpi_keep": "Conservar",
"presets.keep_metadata": "Conservar los metadatos (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/fr.json b/src/Filee.App/Assets/i18n/fr.json
index 68101164..39b124bb 100644
--- a/src/Filee.App/Assets/i18n/fr.json
+++ b/src/Filee.App/Assets/i18n/fr.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "Mettre à l'échelle en pourcentage",
"presets.resize.LongEdge": "Limiter le grand côté",
"presets.resize.Width": "Fixer la largeur",
+ "presets.resize.Custom": "Fixer la largeur et la hauteur",
"presets.rotation": "Faire pivoter",
"presets.rotation.None": "Ne pas faire pivoter",
"presets.rotation.Right90": "90° à droite",
@@ -614,6 +615,8 @@
"presets.percent": "Pourcentage",
"presets.long_edge": "Grand côté (px)",
"presets.width": "Largeur (px)",
+ "presets.height": "Hauteur (px)",
+ "presets.lock_aspect": "Conserver les proportions",
"presets.dpi": "DPI",
"presets.dpi_keep": "Conserver",
"presets.keep_metadata": "Conserver les métadonnées (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.json
index 957153f4..1c98244a 100644
--- a/src/Filee.App/Assets/i18n/hi.json
+++ b/src/Filee.App/Assets/i18n/hi.json
@@ -587,6 +587,7 @@
"presets.resize.Percent": "प्रतिशत से स्केल करें",
"presets.resize.LongEdge": "लंबी भुजा सीमित करें",
"presets.resize.Width": "चौड़ाई तय करें",
+ "presets.resize.Custom": "चौड़ाई और ऊँचाई तय करें",
"presets.rotation": "घुमाएँ",
"presets.rotation.None": "न घुमाएँ",
"presets.rotation.Right90": "दाएँ 90°",
@@ -599,6 +600,8 @@
"presets.percent": "प्रतिशत",
"presets.long_edge": "लंबी भुजा (px)",
"presets.width": "चौड़ाई (px)",
+ "presets.height": "ऊँचाई (px)",
+ "presets.lock_aspect": "अनुपात बनाए रखें",
"presets.dpi": "DPI",
"presets.dpi_keep": "वही रखें",
"presets.keep_metadata": "मेटाडेटा (EXIF) रखें",
diff --git a/src/Filee.App/Assets/i18n/ja.json b/src/Filee.App/Assets/i18n/ja.json
index 5dcc03f9..c7770a19 100644
--- a/src/Filee.App/Assets/i18n/ja.json
+++ b/src/Filee.App/Assets/i18n/ja.json
@@ -587,6 +587,7 @@
"presets.resize.Percent": "倍率を指定",
"presets.resize.LongEdge": "長辺の上限を指定",
"presets.resize.Width": "幅を指定",
+ "presets.resize.Custom": "幅と高さを指定",
"presets.rotation": "回転",
"presets.rotation.None": "回転しない",
"presets.rotation.Right90": "右に90°",
@@ -599,6 +600,8 @@
"presets.percent": "倍率(%)",
"presets.long_edge": "長辺(px)",
"presets.width": "幅(px)",
+ "presets.height": "高さ(px)",
+ "presets.lock_aspect": "縦横比を維持",
"presets.dpi": "DPI",
"presets.dpi_keep": "維持",
"presets.keep_metadata": "メタデータ(EXIF)を保持",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 5e899b54..91b4aa67 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "비율로 조정",
"presets.resize.LongEdge": "긴 변 제한",
"presets.resize.Width": "너비 맞추기",
+ "presets.resize.Custom": "너비와 높이 맞추기",
"presets.rotation": "회전",
"presets.rotation.None": "회전 안 함",
"presets.rotation.Right90": "오른쪽 90°",
@@ -614,6 +615,8 @@
"presets.percent": "비율 (%)",
"presets.long_edge": "긴 변 (px)",
"presets.width": "너비(px)",
+ "presets.height": "높이(px)",
+ "presets.lock_aspect": "가로세로 비율 유지",
"presets.dpi": "DPI",
"presets.dpi_keep": "유지",
"presets.keep_metadata": "메타데이터(EXIF) 유지",
diff --git a/src/Filee.App/Assets/i18n/ne.json b/src/Filee.App/Assets/i18n/ne.json
index a9a85890..e5dbd49d 100644
--- a/src/Filee.App/Assets/i18n/ne.json
+++ b/src/Filee.App/Assets/i18n/ne.json
@@ -587,6 +587,7 @@
"presets.resize.Percent": "प्रतिशतद्वारा स्केल गर्नुहोस्",
"presets.resize.LongEdge": "लामो छेउ सीमित गर्नुहोस्",
"presets.resize.Width": "चौडाइ निर्धारण गर्नुहोस्",
+ "presets.resize.Custom": "चौडाइ र उचाइ निर्धारण गर्नुहोस्",
"presets.rotation": "घुमाउनुहोस्",
"presets.rotation.None": "नघुमाउनुहोस्",
"presets.rotation.Right90": "दायाँ ९०°",
@@ -599,6 +600,8 @@
"presets.percent": "प्रतिशत (%)",
"presets.long_edge": "लामो छेउ (px)",
"presets.width": "चौडाइ (px)",
+ "presets.height": "उचाइ (px)",
+ "presets.lock_aspect": "अनुपात कायम राख्नुहोस्",
"presets.dpi": "DPI",
"presets.dpi_keep": "यथावत राख्नुहोस्",
"presets.keep_metadata": "मेटाडाटा (EXIF) राख्नुहोस्",
diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.json
index 72f4aa02..f8bf9279 100644
--- a/src/Filee.App/Assets/i18n/pl.json
+++ b/src/Filee.App/Assets/i18n/pl.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "Skaluj procentowo",
"presets.resize.LongEdge": "Ogranicz dłuższy bok",
"presets.resize.Width": "Ustaw szerokość",
+ "presets.resize.Custom": "Ustaw szerokość i wysokość",
"presets.rotation": "Obróć",
"presets.rotation.None": "Nie obracaj",
"presets.rotation.Right90": "W prawo 90°",
@@ -614,6 +615,8 @@
"presets.percent": "Procent",
"presets.long_edge": "Dłuższy bok (px)",
"presets.width": "Szerokość (px)",
+ "presets.height": "Wysokość (px)",
+ "presets.lock_aspect": "Zachowaj proporcje",
"presets.dpi": "DPI",
"presets.dpi_keep": "Zachowaj",
"presets.keep_metadata": "Zachowaj metadane (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/pt-BR.json b/src/Filee.App/Assets/i18n/pt-BR.json
index 75099813..6e7768a9 100644
--- a/src/Filee.App/Assets/i18n/pt-BR.json
+++ b/src/Filee.App/Assets/i18n/pt-BR.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "Escala em porcentagem",
"presets.resize.LongEdge": "Limitar o lado maior",
"presets.resize.Width": "Definir a largura",
+ "presets.resize.Custom": "Definir a largura e a altura",
"presets.rotation": "Girar",
"presets.rotation.None": "Não girar",
"presets.rotation.Right90": "90° à direita",
@@ -614,6 +615,8 @@
"presets.percent": "Porcentagem",
"presets.long_edge": "Lado maior (px)",
"presets.width": "Largura (px)",
+ "presets.height": "Altura (px)",
+ "presets.lock_aspect": "Manter a proporção",
"presets.dpi": "DPI",
"presets.dpi_keep": "Manter",
"presets.keep_metadata": "Manter metadados (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/pt-PT.json b/src/Filee.App/Assets/i18n/pt-PT.json
index e6ca7c15..d69d214f 100644
--- a/src/Filee.App/Assets/i18n/pt-PT.json
+++ b/src/Filee.App/Assets/i18n/pt-PT.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "Redimensionar por percentagem",
"presets.resize.LongEdge": "Limitar o lado maior",
"presets.resize.Width": "Definir a largura",
+ "presets.resize.Custom": "Definir a largura e a altura",
"presets.rotation": "Rodar",
"presets.rotation.None": "Não rodar",
"presets.rotation.Right90": "90° à direita",
@@ -614,6 +615,8 @@
"presets.percent": "Percentagem",
"presets.long_edge": "Lado maior (px)",
"presets.width": "Largura (px)",
+ "presets.height": "Altura (px)",
+ "presets.lock_aspect": "Manter a proporção",
"presets.dpi": "DPI",
"presets.dpi_keep": "Manter",
"presets.keep_metadata": "Manter metadados (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/ru.json b/src/Filee.App/Assets/i18n/ru.json
index 29acdd1e..f3d96d86 100644
--- a/src/Filee.App/Assets/i18n/ru.json
+++ b/src/Filee.App/Assets/i18n/ru.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "Масштаб в процентах",
"presets.resize.LongEdge": "Ограничить длинную сторону",
"presets.resize.Width": "Задать ширину",
+ "presets.resize.Custom": "Задать ширину и высоту",
"presets.rotation": "Повернуть",
"presets.rotation.None": "Не поворачивать",
"presets.rotation.Right90": "Вправо на 90°",
@@ -614,6 +615,8 @@
"presets.percent": "Проценты",
"presets.long_edge": "Длинная сторона (px)",
"presets.width": "Ширина (px)",
+ "presets.height": "Высота (px)",
+ "presets.lock_aspect": "Сохранять пропорции",
"presets.dpi": "DPI",
"presets.dpi_keep": "Как есть",
"presets.keep_metadata": "Сохранять метаданные (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/th.json b/src/Filee.App/Assets/i18n/th.json
index 8c419e6b..b13effdc 100644
--- a/src/Filee.App/Assets/i18n/th.json
+++ b/src/Filee.App/Assets/i18n/th.json
@@ -587,6 +587,7 @@
"presets.resize.Percent": "ย่อขยายตามเปอร์เซ็นต์",
"presets.resize.LongEdge": "จำกัดความยาวด้านที่ยาวที่สุด",
"presets.resize.Width": "กำหนดความกว้าง",
+ "presets.resize.Custom": "กำหนดความกว้างและความสูง",
"presets.rotation": "หมุนภาพ",
"presets.rotation.None": "ไม่หมุน",
"presets.rotation.Right90": "ขวา 90°",
@@ -599,6 +600,8 @@
"presets.percent": "เปอร์เซ็นต์",
"presets.long_edge": "ด้านยาวที่สุด (px)",
"presets.width": "ความกว้าง (px)",
+ "presets.height": "ความสูง (px)",
+ "presets.lock_aspect": "รักษาอัตราส่วนภาพ",
"presets.dpi": "DPI",
"presets.dpi_keep": "คงค่าเดิม",
"presets.keep_metadata": "คงข้อมูลเมทาดาตา (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/tr.json b/src/Filee.App/Assets/i18n/tr.json
index 62a8e5e1..0775c655 100644
--- a/src/Filee.App/Assets/i18n/tr.json
+++ b/src/Filee.App/Assets/i18n/tr.json
@@ -587,6 +587,7 @@
"presets.resize.Percent": "Yüzdeyle ölçekle",
"presets.resize.LongEdge": "Uzun kenarı sınırla",
"presets.resize.Width": "Genişliği ayarla",
+ "presets.resize.Custom": "Genişliği ve yüksekliği ayarla",
"presets.rotation": "Döndür",
"presets.rotation.None": "Döndürme",
"presets.rotation.Right90": "Sağa 90°",
@@ -599,6 +600,8 @@
"presets.percent": "Yüzde",
"presets.long_edge": "Uzun kenar (px)",
"presets.width": "Genişlik (px)",
+ "presets.height": "Yükseklik (px)",
+ "presets.lock_aspect": "En boy oranını koru",
"presets.dpi": "DPI",
"presets.dpi_keep": "Koru",
"presets.keep_metadata": "Üst veriyi koru (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 340de83b..d9ed6ba1 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "按百分比缩放",
"presets.resize.LongEdge": "限制长边",
"presets.resize.Width": "设置宽度",
+ "presets.resize.Custom": "设置宽度和高度",
"presets.rotation": "旋转",
"presets.rotation.None": "不旋转",
"presets.rotation.Right90": "向右 90°",
@@ -614,6 +615,8 @@
"presets.percent": "百分比",
"presets.long_edge": "长边 (px)",
"presets.width": "宽度(像素)",
+ "presets.height": "高度(像素)",
+ "presets.lock_aspect": "保持宽高比",
"presets.dpi": "DPI",
"presets.dpi_keep": "保持",
"presets.keep_metadata": "保留元数据 (EXIF)",
diff --git a/src/Filee.App/Assets/i18n/zh-TW.json b/src/Filee.App/Assets/i18n/zh-TW.json
index ee508a74..e93089e4 100644
--- a/src/Filee.App/Assets/i18n/zh-TW.json
+++ b/src/Filee.App/Assets/i18n/zh-TW.json
@@ -602,6 +602,7 @@
"presets.resize.Percent": "按百分比縮放",
"presets.resize.LongEdge": "限制長邊",
"presets.resize.Width": "設定寬度",
+ "presets.resize.Custom": "設定寬度和高度",
"presets.rotation": "旋轉",
"presets.rotation.None": "不旋轉",
"presets.rotation.Right90": "向右 90°",
@@ -614,6 +615,8 @@
"presets.percent": "百分比",
"presets.long_edge": "長邊 (px)",
"presets.width": "寬度(像素)",
+ "presets.height": "高度(像素)",
+ "presets.lock_aspect": "保持長寬比",
"presets.dpi": "DPI",
"presets.dpi_keep": "保持",
"presets.keep_metadata": "保留中繼資料 (EXIF)",
diff --git a/src/Filee.App/ViewModels/PresetEditorViewModel.cs b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
index 44cb482c..919abf3e 100644
--- a/src/Filee.App/ViewModels/PresetEditorViewModel.cs
+++ b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
@@ -160,6 +160,9 @@ public sealed partial class PresetEditorViewModel : ObservableObject
_resizePercent = _edit.Image.ResizePercent;
_longEdge = _edit.Image.LongEdge;
_width = _edit.Image.Width;
+ _customWidth = _edit.Image.CustomWidth;
+ _customHeight = _edit.Image.CustomHeight;
+ _lockAspect = _edit.Image.LockAspect;
_setDpi = _edit.Image.Dpi.HasValue;
_dpi = _edit.Image.Dpi ?? 300;
_keepMetadata = _edit.Image.KeepMetadata;
@@ -385,6 +388,10 @@ public sealed partial class PresetEditorViewModel : ObservableObject
[ObservableProperty] private int _resizePercent;
[ObservableProperty] private int _longEdge;
[ObservableProperty] private int _width;
+ [ObservableProperty] private int _customWidth;
+ [ObservableProperty] private int _customHeight;
+ /// <summary>With Custom: keep each file's shape and fit inside, instead of stretching (ImageOptions.LockAspect).</summary>
+ [ObservableProperty] private bool _lockAspect;
[ObservableProperty] private bool _setDpi;
[ObservableProperty] private int _dpi;
[ObservableProperty]
@@ -636,6 +643,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject
public bool ShowPercent => Resize.Value == ResizeMode.Percent;
public bool ShowLongEdge => Resize.Value == ResizeMode.LongEdge;
public bool ShowWidth => Resize.Value == ResizeMode.Width;
+ public bool ShowCustom => Resize.Value == ResizeMode.Custom;
public bool ShowMargin => PageSize.Value != PdfPageSize.FitImage;
public bool ShowSubfolder => Location.Value == OutputLocation.Subfolder;
public bool ShowCustomFolder => Location.Value == OutputLocation.CustomFolder;
@@ -664,6 +672,9 @@ public sealed partial class PresetEditorViewModel : ObservableObject
image.ResizePercent = Math.Clamp(ResizePercent, 1, 1000);
image.LongEdge = Math.Clamp(LongEdge, 16, 20000);
image.Width = Math.Clamp(Width, 16, 20000);
+ image.CustomWidth = Math.Clamp(CustomWidth, 16, 16384);
+ image.CustomHeight = Math.Clamp(CustomHeight, 16, 16384);
+ image.LockAspect = LockAspect;
image.Dpi = SetDpi ? Math.Clamp(Dpi, 36, 2400) : null;
image.KeepMetadata = KeepMetadata;
image.KeepColorProfile = KeepColorProfile;
diff --git a/src/Filee.App/Views/PresetEditorView.axaml b/src/Filee.App/Views/PresetEditorView.axaml
index 703b84fe..469f3d19 100644
--- a/src/Filee.App/Views/PresetEditorView.axaml
+++ b/src/Filee.App/Views/PresetEditorView.axaml
@@ -128,6 +128,19 @@
<TextBlock Classes="label" Text="{DynamicResource presets.width}" />
<NumericUpDown Value="{Binding Width}" Minimum="16" Maximum="20000" Increment="100" FormatString="0" AutomationProperties.Name="{DynamicResource presets.width}" />
</StackPanel>
+ <StackPanel Grid.Column="2" IsVisible="{Binding ShowCustom}">
+ <Grid ColumnDefinitions="*,8,*">
+ <StackPanel>
+ <TextBlock Classes="label" Text="{DynamicResource presets.width}" />
+ <NumericUpDown Value="{Binding CustomWidth}" Minimum="16" Maximum="16384" Increment="10" FormatString="0" AutomationProperties.Name="{DynamicResource presets.width}" />
+ </StackPanel>
+ <StackPanel Grid.Column="2">
+ <TextBlock Classes="label" Text="{DynamicResource presets.height}" />
+ <NumericUpDown Value="{Binding CustomHeight}" Minimum="16" Maximum="16384" Increment="10" FormatString="0" AutomationProperties.Name="{DynamicResource presets.height}" />
+ </StackPanel>
+ </Grid>
+ <CheckBox Content="{DynamicResource presets.lock_aspect}" IsChecked="{Binding LockAspect}" Margin="0,8,0,0" AutomationProperties.Name="{DynamicResource presets.lock_aspect}" />
+ </StackPanel>
</Grid>
<Grid ColumnDefinitions="*,12,*">
<StackPanel>
diff --git a/src/Filee.Core/Presets/Preset.cs b/src/Filee.Core/Presets/Preset.cs
index e7767cb7..76b4ef1a 100644
--- a/src/Filee.Core/Presets/Preset.cs
+++ b/src/Filee.Core/Presets/Preset.cs
@@ -265,6 +265,11 @@ public enum ResizeMode
LongEdge,
/// <summary>Scale to <see cref="ImageOptions.Width"/> pixels wide, height in proportion (never upscales).</summary>
Width,
+ /// <summary>
+ /// Scale to <see cref="ImageOptions.CustomWidth"/> x <see cref="ImageOptions.CustomHeight"/> pixels: stretched to exactly that
+ /// size, or with <see cref="ImageOptions.LockAspect"/> scaled (up or down) to the largest size that fits inside.
+ /// </summary>
+ Custom,
}
/// <summary>How an image is turned, after its EXIF orientation is applied.</summary>
@@ -334,6 +339,18 @@ public sealed class ImageOptions
/// <summary>Target width in pixels when <see cref="Resize"/> is <see cref="ResizeMode.Width"/>.</summary>
public int Width { get; set; } = 1200;
+ /// <summary>Target width in pixels when <see cref="Resize"/> is <see cref="ResizeMode.Custom"/> (issue #576).</summary>
+ public int CustomWidth { get; set; } = 1920;
+
+ /// <summary>Target height in pixels when <see cref="Resize"/> is <see cref="ResizeMode.Custom"/> (issue #576).</summary>
+ public int CustomHeight { get; set; } = 1080;
+
+ /// <summary>
+ /// With <see cref="ResizeMode.Custom"/>: keep each file's own shape and scale it to the largest size that fits inside
+ /// <see cref="CustomWidth"/> x <see cref="CustomHeight"/>, instead of stretching it to exactly that size.
+ /// </summary>
+ public bool LockAspect { get; set; }
+
/// <summary>Output DPI written into the file. <c>null</c> keeps the source value.</summary>
public int? Dpi { get; set; }
diff --git a/src/Filee.Engines/Magick/ImageEncoder.cs b/src/Filee.Engines/Magick/ImageEncoder.cs
index 2ee7fe8b..c2b2d9eb 100644
--- a/src/Filee.Engines/Magick/ImageEncoder.cs
+++ b/src/Filee.Engines/Magick/ImageEncoder.cs
@@ -290,6 +290,21 @@ internal static class ImageEncoder
case ResizeMode.Width when options.Width > 0 && image.Width > options.Width:
image.Resize((uint)options.Width, (uint)Math.Max(1, Math.Round(image.Height * (double)options.Width / image.Width)));
break;
+ case ResizeMode.Custom when options.CustomWidth > 0 && options.CustomHeight > 0 && options.LockAspect:
+ {
+ // The file's own shape is kept: scaled up or down to the largest size that fits inside the box. Both
+ // sides come from one scale, so the aspect already matches and Resize keeps it, as it always does.
+ var scale = Math.Min(options.CustomWidth / (double)image.Width, options.CustomHeight / (double)image.Height);
+ if (scale != 1)
+ image.Resize((uint)Math.Max(1, Math.Round(image.Width * scale)), (uint)Math.Max(1, Math.Round(image.Height * scale)));
+ break;
+ }
+ case ResizeMode.Custom when options.CustomWidth > 0 && options.CustomHeight > 0:
+ // No lock: exactly the asked size, stretching or squeezing the picture on purpose (issue #576). Resize
+ // fits inside a box and keeps the aspect on its own, so the flag is what makes this a real stretch.
+ if (image.Width != (uint)options.CustomWidth || image.Height != (uint)options.CustomHeight)
+ image.Resize(new MagickGeometry((uint)options.CustomWidth, (uint)options.CustomHeight) { IgnoreAspectRatio = true });
+ break;
}
FitFormat(image, targetFormat);
diff --git a/src/Filee.Engines/Vector/VectorConverter.cs b/src/Filee.Engines/Vector/VectorConverter.cs
index 78ddfabf..7d2a7459 100644
--- a/src/Filee.Engines/Vector/VectorConverter.cs
+++ b/src/Filee.Engines/Vector/VectorConverter.cs
@@ -120,9 +120,11 @@ public sealed class VectorConverter : IConverter, IImageTransformer
ct.ThrowIfCancellationRequested();
progress?.Report(0.6);
- // The drawing was rendered at its final size, so the preset's resize must not scale the bitmap again.
+ // The drawing was rendered at its final size, so the preset's resize must not scale the bitmap again. A custom
+ // width x height is different: it is an exact stretch of whatever the render produced, so it applies afterwards.
var options = step.Preset.Image.Clone();
- options.Resize = Core.Presets.ResizeMode.None;
+ if (options.Resize is not Core.Presets.ResizeMode.Custom)
+ options.Resize = Core.Presets.ResizeMode.None;
ImageEncoder.ApplyOptions(image, options, step.To);
return ImageEncoder.Write([image], step.To, step.Output, options);
}
diff --git a/tests/Filee.Engines.Tests/GraphicsTests.cs b/tests/Filee.Engines.Tests/GraphicsTests.cs
index 5a2fb37e..be34091a 100644
--- a/tests/Filee.Engines.Tests/GraphicsTests.cs
+++ b/tests/Filee.Engines.Tests/GraphicsTests.cs
@@ -423,6 +423,23 @@ public class GraphicsTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal(200u, png.Width);
}
+ [Fact]
+ public async Task Custom_resize_stretches_a_vector_picture()
+ {
+ var dir = fx.NewFolder();
+ var svg = Write(dir, "logo.svg", GraphicsBuilders.Svg);
+
+ var rendered = await fx.ConvertAsync([svg], new Preset
+ {
+ TargetFormat = "png",
+ Image = { Resize = ResizeMode.Custom, CustomWidth = 777, CustomHeight = 333 },
+ });
+
+ AssertDone(rendered);
+ using var png = new MagickImage(rendered.Outputs.Single());
+ Assert.Equal((777u, 333u), (png.Width, png.Height));
+ }
+
[Fact]
public async Task Files_that_are_not_svg_fail_with_a_message()
{
diff --git a/tests/Filee.Engines.Tests/ImageAndPdfTests.cs b/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
index e18d0ad1..4384dae5 100644
--- a/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
+++ b/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
@@ -304,6 +304,45 @@ public class ImageAndPdfTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal((800u, 2000u), (narrow.Width, narrow.Height));
}
+ [Fact]
+ public void Custom_resize_stretches_to_exactly_the_asked_size()
+ {
+ // The case from the issue: a 1080 x 1920 photo asked for a 500 x 2000 banner, distorted on purpose.
+ var options = new ImageOptions { Resize = ResizeMode.Custom, CustomWidth = 500, CustomHeight = 2000 };
+ using var portrait = new MagickImage(MagickColors.White, 1080, 1920);
+
+ Filee.Engines.Magick.ImageEncoder.ApplyOptions(portrait, options, "png");
+
+ Assert.Equal((500u, 2000u), (portrait.Width, portrait.Height));
+ }
+
+ [Fact]
+ public void Custom_resize_with_the_lock_fits_inside_without_distortion()
+ {
+ var options = new ImageOptions { Resize = ResizeMode.Custom, CustomWidth = 500, CustomHeight = 2000, LockAspect = true };
+
+ // The width is the limit: 1080 x 1920 shrinks to the largest 9:16 fit inside the box, 500 x 889.
+ using var portrait = new MagickImage(MagickColors.White, 1080, 1920);
+ Filee.Engines.Magick.ImageEncoder.ApplyOptions(portrait, options, "png");
+ Assert.Equal((500u, 889u), (portrait.Width, portrait.Height));
+
+ // The lock grows as well: 250 x 444 doubles to 500 x 888, the same shape.
+ using var small = new MagickImage(MagickColors.White, 250, 444);
+ Filee.Engines.Magick.ImageEncoder.ApplyOptions(small, options, "png");
+ Assert.Equal((500u, 888u), (small.Width, small.Height));
+ }
+
+ [Fact]
+ public void Custom_resize_leaves_a_picture_that_already_has_the_asked_size()
+ {
+ var options = new ImageOptions { Resize = ResizeMode.Custom, CustomWidth = 500, CustomHeight = 2000 };
+ using var exact = new MagickImage(MagickColors.White, 500, 2000);
+
+ Filee.Engines.Magick.ImageEncoder.ApplyOptions(exact, options, "png");
+
+ Assert.Equal((500u, 2000u), (exact.Width, exact.Height));
+ }
+
[Fact]
public void A_long_image_splits_between_pages_into_parts_the_format_holds()
{