Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Update from main #104

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions ContactAppCore/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,12 @@ public string AddPhoto(Stream stream, string name, string file, int height, int
errorMessage = $"Error: File does not match minimum dimensions {minimumWidth} width and {minimumHeight} height (actual file is {img.Width}x{img.Height})";
return "";
}
if (img.Width != width || img.Height != height) {
var originalHeight = img.Height;
var originalWidth = img.Width;
img.Mutate(i => i.Resize(width, 0));
if (img.Height > height) {
img.Mutate(i => i.Crop(new Rectangle(0, (img.Height - height) / 2, width, height)));
using var memoryStreamWebP = new MemoryStream();
img.SaveAsWebp(memoryStreamWebP);
errorMessage = "";
return AddFile(memoryStreamWebP, "profile_photo", name, Path.GetFileNameWithoutExtension(file) + ".webp").Result;
} else {
errorMessage = $"Error: File does not match dimensions and cannot be cropped (actual file is {originalWidth} width by {originalHeight} height)";
return "";
}
}
errorMessage = "";
img.Mutate(i => i.Resize(width, 0));
img.Mutate(i => i.Crop(new Rectangle(0, (img.Height - height) / 2, width, height)));
using var memoryStreamWebP = new MemoryStream();
img.SaveAsWebp(memoryStreamWebP);
return AddFile(memoryStreamWebP, "profile_photo", name, Path.GetFileNameWithoutExtension(file) + ".webp").Result;
}
errorMessage = "";
return AddFile(stream, "profile_photo", name, file).Result;
Expand Down
Loading