Does anybody of you know if there is something happening when changing the format of an image to webp? We have the situation here that it looses colour when being converted from jpg or png to webp. We are using ImageSharp.
public static string? GetOptimisedCropUrl(this IPublishedContent? image, string crop, bool convertWebp=true) {
if (image == null) {
return null;
}
var webpAppendix = "&format=webp&orient=false";
if (!convertWebp) {
webpAppendix = "&format=jpg&quality=80";
}
if (!string.IsNullOrWhiteSpace(crop)) return image.GetCropUrl(crop) + webpAppendix;
var imageHeight = image.GetProperty("height")?.GetValue()?.SafeCast<int>();
var imageWidth = image.GetProperty("width")?.GetValue()?.SafeCast<int>();
if (imageHeight is >= 1440 && imageWidth is >= 2560) {
return image.GetCropUrl("LargeImageCrop") + webpAppendix;
}
return image.Url() + "?width=" + imageWidth + "&height=" + imageHeight + webpAppendix;
}