Last active
November 8, 2021 17:38
-
-
Save tristolliday/cd483f369a06f45ef3645a77bce76adb to your computer and use it in GitHub Desktop.
Responsive, high performance images in umbraco 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@* /Views/Partials/ResponsiveImage.cshtml *@ | |
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage | |
@using Umbraco.Cms.Core.Media | |
@using Umbraco.Cms.Core.Models.PublishedContent | |
@using Umbraco.Cms.Core.Routing | |
@{ | |
var publishedContent = @ViewData["publishedContent"] as IPublishedContent ?? null; | |
var lazyLoading = @ViewData["lazyLoading"] ?? false; | |
@* var imageWebP = publishedContent?.GetCropUrl(width: 600, height: 20, quality:80, furtherOptions: "&format=webp") ?? ""; Webp not yet available on SixLabors.ImageSharp*@ | |
var imageJpeg = publishedContent?.GetCropUrl(width: 600, height: 20, quality:80, furtherOptions: "&format=jpg") ?? ""; | |
var imageOriginal = publishedContent?.GetCropUrl(600, 20) ?? ""; | |
} | |
<picture> | |
@* <source srcset="@imageWebP" type="image/webp"> *@ | |
<source srcset="@imageJpeg" type='image/jpeg'> | |
<img src="@imageOriginal" width="600" height="20" loading="@lazyLoading" height="20" alt="" /> | |
</picture> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment