blob: dd2e07c95c9583bda9e5524d1c824453fa8337d3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
using System;
using System.Diagnostics;
using System.IO;
using ImageMagick;
using IOL.Helpers;
using VSH.Data.Static;
namespace VSH.Utilities;
public static class ImageFunctions
{
private static MagickGeometry SmallGeometry => new(300);
private static MagickGeometry MiniGeometry => new(150);
private static MagickGeometry NormalGeometry => new(1280, 720);
public static void CreateProductImageCollection(FileInfo path) {
try {
using var image = new MagickImage(path);
if (image.Width > NormalGeometry.Width) {
image.Resize(NormalGeometry);
image.Write(path);
}
Debug.WriteLine(path.Name);
if (image.Width > SmallGeometry.Width) {
var fileName = Path.Combine(path.DirectoryName ?? AppPaths.ProductImages.HostPath,
path.Name.ExtractFileName() + "-300" + path.Extension);
if (!File.Exists(fileName)) {
image.Resize(SmallGeometry);
image.Write(fileName);
}
}
if (image.Width > MiniGeometry.Width) {
var fileName = Path.Combine(path.DirectoryName ?? AppPaths.ProductImages.HostPath,
path.Name.ExtractFileName() + "-150" + path.Extension);
if (!File.Exists(fileName)) {
image.Resize(MiniGeometry);
image.Write(fileName);
}
}
} catch (Exception e) {
Console.WriteLine(e);
throw;
}
}
public static void EnsureNormalOrLessImageResolution(FileInfo path) {
try {
using var image = new MagickImage(path);
if (image.Width <= NormalGeometry.Width)
return;
image.Resize(NormalGeometry);
image.Write(path);
} catch (Exception e) {
Console.WriteLine(e);
throw;
}
}
}
|