picture
tags are the future of img
tags. But it can be messy to create them, so here goes 😉. This example will return a small image if your screen is small, a large one otherwise. Try resizing the width of your browser to test. The image will become blurry if the browser is less than 800px wide.
⬇️ Result | Source ➡️
<picture><source srcset='/Portals/tutorials/2sxc/Tutorial-Razor/tutorials/razorblade-img/img/%C3%BCberschrift-large.png' media='(min-width: 800px)'><img src='/Portals/tutorials/2sxc/Tutorial-Razor/tutorials/razorblade-img/img/%C3%BCberschrift-small.png'></picture>
@inherits Custom.Hybrid.Razor14
@using ToSic.Razor.Blade
@{
// Initial Code
// demo of path with umlauts and japanese characters
var path = App.Path + "/tutorials/razorblade-img/img/";
var small = "überschrift-small.png";
var large = "überschrift-large.png";
}
@Tag.Picture(
Tag.Source().Srcset(path + large).Media("(min-width: 800px)"),
Tag.Img().Src(path + small))
@* Source Code *@
<code>@Tag.Picture(
Tag.Source().Srcset(path + large).Media("(min-width: 800px)"),
Tag.Img().Src(path + small)).ToString()
</code>