-
-
Save villian/a5daff6daf24f541b0f8bab7f17011ba 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 | |
@inject IPublishedValueFallback PublishedValueFallback | |
@inject IPublishedUrlProvider PublishedUrlProvider | |
@inject IImageUrlGenerator ImageUrlGenerator | |
@{ | |
var publishedContent = @ViewData["publishedContent"] as IPublishedContent ?? null; | |
var lazyLoading = @ViewData["lazyLoading"] ?? false; | |
var imageWebP = publishedContent?.GetCropUrl(ImageUrlGenerator, PublishedValueFallback, PublishedUrlProvider, width: 600, height: 20, quality:80, furtherOptions: "&format=webp") ?? ""; | |
var imageJpeg = publishedContent?.GetCropUrl(ImageUrlGenerator, PublishedValueFallback, PublishedUrlProvider, width: 600, height: 20, quality:80, furtherOptions: "&format=jpg") ?? ""; | |
var imageOriginal = publishedContent?.GetCropUrl(ImageUrlGenerator, PublishedValueFallback, PublishedUrlProvider, 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