Link.Image(...)
Above you can see that you shouldn't do src='@imgUrl' because it can cause trouble in a CMS - like when the image has special characters in the name. So you should always use @Link.Image(imgUrl) instead. The Link.Image also makes it easy to create image urls containing the correct resize parameters. Even better: The parameters can be in a global setting for re-use across all apps and templates.
src='@imgUrl'
@Link.Image(imgUrl)
Link.Image
2sxc comes with a built-in image resizer. V12 and before used ImageResizer.net, while v13 now uses imageflow. They work the same way.
The core principles:
?w=200
?w=200&h=150
mode=crop
For starters - this is the image we'll resize later on:
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(imgUrl)'>
Look at the source-code below to see how they are made. Note that we're adding a pink border around all img tags to make it easier to see the image bounds.
img
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(url: imgUrl, width: 200)'>
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(url: imgUrl, height: 150)'>
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(url: imgUrl, width: 200, height: 150)'>
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(url: imgUrl, width: 200, format: "jpg")'>
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(url: imgUrl, width: 200, format: "jpg", quality: 15)'>
crop
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(url: imgUrl, width: 250, height: 150, resizeMode: "crop")'>
max
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(url: imgUrl, width: 250, height: 150, resizeMode: "max")'>
stretch
@inherits Custom.Hybrid.Razor14 @{ var imgUrl = App.Path + "/assets/img-resize/basic-logo.png"; } <img loading="lazy" src='@Link.Image(url: imgUrl, width: 250, height: 150, resizeMode: "stretch")'>
Other modes not demonstrated here, see Image Resizer docs.