As learned in the previous tutorials the picture
tag can be created out of URLs. The image service can also be used with Fields. The field will contain the URL as well as additional Metadata like the description or what part of the picture is important (the Crop-Anchor).
To get the most out of 2sxc and its image configuration options it's best to use the image object instead of URLs. By using the image configuration options, the settings can be easily retrieved from the corresponding image.
-
-
-
-
-
Picture from Content.Image
Picture from Field
containing crop anchor and alt text
@inherits Custom.Hybrid.Razor14
<div class="row">
<div class="col-md">
<p><strong>Picture from <code>Content.Image</code></strong></p>
@* Picture from Content.Image *@
@Kit.Image.Picture(Content.Image)
</div>
<div class="col-md">
<p><strong>Picture from <code>Field</code> containing crop anchor and alt text</strong></p>
@* Picture from Field containing crop anchor and alt text *@
@Kit.Image.Picture(Content.Field("Image"))
</div>
</div>
<picture>
<source type='image/webp'
srcset='/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=2460&h=1520&quality=75&mode=crop&scale=both&format=webp 2460w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=1230&h=760&quality=75&mode=crop&scale=both&format=webp 1230w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=922&h=569&quality=75&mode=crop&scale=both&format=webp 922w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=615&h=380&quality=75&mode=crop&scale=both&format=webp 615w'
sizes='(max-width: 1400px) 100vw,
1230px'>
<source type='image/jpeg'
srcset='/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=2460&h=1520&quality=75&mode=crop&scale=both 2460w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=1230&h=760&quality=75&mode=crop&scale=both 1230w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=922&h=569&quality=75&mode=crop&scale=both 922w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=615&h=380&quality=75&mode=crop&scale=both 615w'
sizes='(max-width: 1400px) 100vw,
1230px'>
<img src='/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=1230&h=760&quality=75&mode=crop&scale=both'
loading='lazy'
class='img-fluid'
width='1230'
height='760'>
</picture>
<picture>
<source type='image/webp'
srcset='/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=2460&h=1520&quality=75&mode=crop&scale=both&format=webp&anchor=bottomcenter 2460w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=1230&h=760&quality=75&mode=crop&scale=both&format=webp&anchor=bottomcenter 1230w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=922&h=569&quality=75&mode=crop&scale=both&format=webp&anchor=bottomcenter 922w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=615&h=380&quality=75&mode=crop&scale=both&format=webp&anchor=bottomcenter 615w'
sizes='(max-width: 1400px) 100vw,
1230px'>
<source type='image/jpeg'
srcset='/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=2460&h=1520&quality=75&mode=crop&scale=both&anchor=bottomcenter 2460w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=1230&h=760&quality=75&mode=crop&scale=both&anchor=bottomcenter 1230w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=922&h=569&quality=75&mode=crop&scale=both&anchor=bottomcenter 922w,
/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=615&h=380&quality=75&mode=crop&scale=both&anchor=bottomcenter 615w'
sizes='(max-width: 1400px) 100vw,
1230px'>
<img src='/Portals/tutorials/adam/Tutorial-Razor/1eSr_DjJnk-67Zdd4-fw2Q/Image/photo-1651590814269-ccf8dee671ae.jpg?w=1230&h=760&quality=75&mode=crop&scale=both&anchor=bottomcenter'
loading='lazy'
alt='This description was retrieved from the image metadata'
class='img-fluid'
width='1230'
height='760'>
</picture>
View Configuration
This is how this view would be configured for this sample.
- Content/Item ContentType: ImgDemoData
- Content/Item Data:
- file:6208 (ID: 49116)