Skip to content

Instantly share code, notes, and snippets.

@tristolliday
Last active November 8, 2021 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tristolliday/cd483f369a06f45ef3645a77bce76adb to your computer and use it in GitHub Desktop.
Save tristolliday/cd483f369a06f45ef3645a77bce76adb to your computer and use it in GitHub Desktop.
Responsive, high performance images in umbraco 9
@* /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