mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Switch to webp
This commit is contained in:
parent
74c31a0f18
commit
7b2f44d19a
@ -56,7 +56,7 @@ namespace Kyoo.Core.Controllers
|
|||||||
|
|
||||||
private static async Task _WriteTo(SKBitmap bitmap, string path)
|
private static async Task _WriteTo(SKBitmap bitmap, string path)
|
||||||
{
|
{
|
||||||
SKData data = bitmap.Encode(SKEncodedImageFormat.Jpeg, 18);
|
SKData data = bitmap.Encode(SKEncodedImageFormat.Webp, 18);
|
||||||
await using Stream reader = data.AsStream();
|
await using Stream reader = data.AsStream();
|
||||||
await using Stream file = File.Create(path);
|
await using Stream file = File.Create(path);
|
||||||
await reader.CopyToAsync(file);
|
await reader.CopyToAsync(file);
|
||||||
@ -80,13 +80,13 @@ namespace Kyoo.Core.Controllers
|
|||||||
using SKBitmap original = SKBitmap.Decode(codec, info);
|
using SKBitmap original = SKBitmap.Decode(codec, info);
|
||||||
|
|
||||||
using SKBitmap high = original.Resize(new SKSizeI(original.Width, original.Height), SKFilterQuality.High);
|
using SKBitmap high = original.Resize(new SKSizeI(original.Width, original.Height), SKFilterQuality.High);
|
||||||
await _WriteTo(high, $"{localPath}.{ImageQuality.High.ToString().ToLowerInvariant()}.jpg");
|
await _WriteTo(high, $"{localPath}.{ImageQuality.High.ToString().ToLowerInvariant()}.webp");
|
||||||
|
|
||||||
using SKBitmap medium = high.Resize(new SKSizeI((int)(high.Width / 1.5), (int)(high.Height / 1.5)), SKFilterQuality.Medium);
|
using SKBitmap medium = high.Resize(new SKSizeI((int)(high.Width / 1.5), (int)(high.Height / 1.5)), SKFilterQuality.Medium);
|
||||||
await _WriteTo(medium, $"{localPath}.{ImageQuality.Medium.ToString().ToLowerInvariant()}.jpg");
|
await _WriteTo(medium, $"{localPath}.{ImageQuality.Medium.ToString().ToLowerInvariant()}.webp");
|
||||||
|
|
||||||
using SKBitmap low = medium.Resize(new SKSizeI(medium.Width / 2, medium.Height / 2), SKFilterQuality.Low);
|
using SKBitmap low = medium.Resize(new SKSizeI(medium.Width / 2, medium.Height / 2), SKFilterQuality.Low);
|
||||||
await _WriteTo(low, $"{localPath}.{ImageQuality.Low.ToString().ToLowerInvariant()}.jpg");
|
await _WriteTo(low, $"{localPath}.{ImageQuality.Low.ToString().ToLowerInvariant()}.webp");
|
||||||
|
|
||||||
image.Blurhash = Blurhasher.Encode(low, 4, 3);
|
image.Blurhash = Blurhasher.Encode(low, 4, 3);
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ namespace Kyoo.Core.Controllers
|
|||||||
public string GetImagePath<T>(T item, string image, ImageQuality quality)
|
public string GetImagePath<T>(T item, string image, ImageQuality quality)
|
||||||
where T : IThumbnails
|
where T : IThumbnails
|
||||||
{
|
{
|
||||||
return $"{_GetBaseImagePath(item, image)}.{quality.ToString().ToLowerInvariant()}.jpg";
|
return $"{_GetBaseImagePath(item, image)}.{quality.ToString().ToLowerInvariant()}.webp";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ namespace Kyoo.Core.Api
|
|||||||
string path = _thumbs.GetImagePath(resource, image, quality ?? ImageQuality.High);
|
string path = _thumbs.GetImagePath(resource, image, quality ?? ImageQuality.High);
|
||||||
if (path == null || !System.IO.File.Exists(path))
|
if (path == null || !System.IO.File.Exists(path))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
return PhysicalFile(Path.GetFullPath(path), "image/jpeg", true);
|
return PhysicalFile(Path.GetFullPath(path), "image/webp", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user