Skip to content

Commit

Permalink
Remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpotts committed Mar 28, 2024
1 parent 03f9817 commit e65bea6
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/Application/Services/RecipeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,38 +142,34 @@ public async Task UpdateCoverImageAsync(
$"User is unauthorized to perform {nameof(Operations.Update)} operation on resource.");
}

await Task.Run(async () =>
{
SKBitmap bitmap = SKBitmap.Decode(imageData)
?? throw new ArgumentException("The image could not be decoded.", nameof(imageData));
SKBitmap bitmap = SKBitmap.Decode(imageData)
?? throw new ArgumentException("The image could not be decoded.", nameof(imageData));

try
try
{
if (bitmap.Width > MaxImageDimension || bitmap.Height > MaxImageDimension)
{
if (bitmap.Width > MaxImageDimension || bitmap.Height > MaxImageDimension)
{
var scaleFactor = (double)MaxImageDimension / Math.Max(bitmap.Width, bitmap.Height);
var width = (int)Math.Floor(bitmap.Width * scaleFactor);
var height = (int)Math.Floor(bitmap.Height * scaleFactor);
var scaleFactor = (double)MaxImageDimension / Math.Max(bitmap.Width, bitmap.Height);
var width = (int)Math.Floor(bitmap.Width * scaleFactor);
var height = (int)Math.Floor(bitmap.Height * scaleFactor);

var resizedBitmap = bitmap.Resize(new SKImageInfo(width, height), ImageFilterQuality);
var resizedBitmap = bitmap.Resize(new SKImageInfo(width, height), ImageFilterQuality);

bitmap.Dispose();
bitmap = resizedBitmap;
}

using var data = bitmap.Encode(SKEncodedImageFormat.Webp, ImageQuality);

await File.WriteAllBytesAsync(
Path.Combine(s_imagesDirectory, $"{id}.webp"),
data.AsSpan().ToArray(),
cancellationToken);
}
finally
{
bitmap.Dispose();
bitmap = resizedBitmap;
}
},
cancellationToken);

using var data = bitmap.Encode(SKEncodedImageFormat.Webp, ImageQuality);

await File.WriteAllBytesAsync(
Path.Combine(s_imagesDirectory, $"{id}.webp"),
data.AsSpan().ToArray(),
cancellationToken);
}
finally
{
bitmap.Dispose();
}

recipe.CoverImage ??= new();
recipe.CoverImage.Url = $"{id}.webp";
Expand Down

0 comments on commit e65bea6

Please sign in to comment.