@@ -146,6 +146,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
146
146
var placeholderImgSrc = string . Empty ;
147
147
var jsLazyLoad = ! _globalSettings . OurImg . UseNativeLazyLoading && ! AboveTheFold ;
148
148
var style = ImgStyle ;
149
+ var hasLqip = _globalSettings . OurImg . LazyLoadPlaceholder . Equals ( ImagePlaceholderType . LowQualityImage ) ;
149
150
150
151
if ( MediaItem is not null )
151
152
{
@@ -154,12 +155,13 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
154
155
var originalWidth = media . GetValue < double > ( "umbracoWidth" ) ; // Determine the width from the originally uploaded image
155
156
var originalHeight = media . GetValue < double > ( "umbracoHeight" ) ; // Determine the height from the originally uploaded image
156
157
width = ImgWidth > 0 ? ImgWidth : originalWidth ; // If the element wasn't provided with a width property, use the width from the media object instead
158
+
157
159
if ( ! string . IsNullOrEmpty ( ImgCropAlias ) )
158
160
{
159
161
// The element contains a crop alias property, so pull through a cropped version of the original image
160
162
// Also, calculate the height based on the given width using the crop profile so it's to scale
161
163
imgSrc = MediaItem . GetCropUrl ( width : ( int ) width , cropAlias : ImgCropAlias ) ;
162
- if ( _globalSettings . OurImg . LazyLoadPlaceholder . Equals ( ImagePlaceholderType . LowQualityImage ) )
164
+ if ( hasLqip )
163
165
{
164
166
// Generate a low quality placeholder image if configured to do so
165
167
placeholderImgSrc = MediaItem . GetCropUrl ( width : ImgWidth , cropAlias : ImgCropAlias , quality : _globalSettings . OurImg . LazyLoadPlaceholderLowQualityImageQuality ) ;
@@ -170,14 +172,28 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
170
172
}
171
173
else
172
174
{
173
- // Pull through an image based on the given width and calculate the height so it's to scale.
174
- imgSrc = MediaItem . GetCropUrl ( width : ( int ) width ) ;
175
- if ( _globalSettings . OurImg . LazyLoadPlaceholder . Equals ( ImagePlaceholderType . LowQualityImage ) )
175
+ if ( ImgHeight > 0 )
176
176
{
177
- // Generate a low quality placeholder image if configured to do so
178
- placeholderImgSrc = MediaItem . GetCropUrl ( width : ( int ) width , quality : _globalSettings . OurImg . LazyLoadPlaceholderLowQualityImageQuality ) ;
177
+ imgSrc = MediaItem . GetCropUrl ( width : ( int ) ImgWidth , height : ( int ) ImgHeight ) ;
178
+ if ( hasLqip )
179
+ {
180
+ // Generate a low quality placeholder image if configured to do so
181
+ placeholderImgSrc = MediaItem . GetCropUrl ( width : ( int ) ImgWidth , height : ( int ) ImgHeight , quality : _globalSettings . OurImg . LazyLoadPlaceholderLowQualityImageQuality ) ;
182
+ }
183
+ width = ImgWidth ;
184
+ height = ImgHeight != 0 ? ImgHeight : ( originalHeight / originalWidth ) * width ;
185
+ }
186
+ else
187
+ {
188
+ // Pull through an image based on the given width and calculate the height so it's to scale.
189
+ imgSrc = MediaItem . GetCropUrl ( width : ( int ) width ) ;
190
+ if ( hasLqip )
191
+ {
192
+ // Generate a low quality placeholder image if configured to do so
193
+ placeholderImgSrc = MediaItem . GetCropUrl ( width : ( int ) width , quality : _globalSettings . OurImg . LazyLoadPlaceholderLowQualityImageQuality ) ;
194
+ }
195
+ height = ( originalHeight / originalWidth ) * width ;
179
196
}
180
- height = ( originalHeight / originalWidth ) * width ;
181
197
}
182
198
183
199
#region Autogenerate alt text if unspecfied
@@ -199,7 +215,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
199
215
width = ImgWidth ;
200
216
height = ImgHeight ;
201
217
202
- imgSrc = AddQueryToUrl ( FileSource , "width" , width . ToString ( ) ) ;
218
+ imgSrc = AddQueryToUrl ( FileSource , "width" , width . ToString ( ) ) + "&height=" + height . ToString ( ) ;
203
219
204
220
#region Autogenerate alt text if unspecfied
205
221
if ( string . IsNullOrWhiteSpace ( ImgAlt ) )
@@ -264,7 +280,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
264
280
if ( jsLazyLoad )
265
281
{
266
282
output . Attributes . Add ( "data-src" , imgSrc ) ;
267
- if ( _globalSettings . OurImg . LazyLoadPlaceholder . Equals ( ImagePlaceholderType . LowQualityImage ) && ! string . IsNullOrEmpty ( placeholderImgSrc ) )
283
+ if ( hasLqip && ! string . IsNullOrEmpty ( placeholderImgSrc ) )
268
284
{
269
285
output . Attributes . Add ( "src" , placeholderImgSrc ) ;
270
286
}
@@ -349,15 +365,26 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
349
365
var cropWidth = MediaItem . LocalCrops . GetCrop ( cropAlias ) . Width ;
350
366
var cropHeight = MediaItem . LocalCrops . GetCrop ( cropAlias ) . Height ;
351
367
sourceHeight = ( StringUtils . GetDouble ( cropHeight ) / StringUtils . GetDouble ( cropWidth ) ) * size . ImageWidth ;
352
- }
353
368
354
- sb . AppendLine ( $ "<source { ( jsLazyLoad ? "data-" : "" ) } srcset=\" { MediaItem . GetCropUrl ( width : size . ImageWidth , cropAlias : cropAlias ) } \" media=\" ({ ( _globalSettings . OurImg . MobileFirst ? $ "min-width: { minWidth } " : $ "max-width: { minWidth - 1 } ") } px)\" width=\" { size . ImageWidth } \" { ( sourceHeight > 0 ? $ " height=\" { sourceHeight } \" " : "" ) } />") ;
369
+ sb . AppendLine ( $ "<source { ( jsLazyLoad ? "data-" : "" ) } srcset=\" { MediaItem . GetCropUrl ( width : size . ImageWidth , cropAlias : cropAlias ) } \" media=\" ({ ( _globalSettings . OurImg . MobileFirst ? $ "min-width: { minWidth } " : $ "max-width: { minWidth - 1 } ") } px)\" width=\" { size . ImageWidth } \" { ( sourceHeight > 0 ? $ " height=\" { sourceHeight } \" " : "" ) } />") ;
370
+ }
371
+ else
372
+ {
373
+ if ( size . ImageHeight > 0 )
374
+ {
375
+ sb . AppendLine ( $ "<source { ( jsLazyLoad ? "data-" : "" ) } srcset=\" { MediaItem . GetCropUrl ( width : size . ImageWidth , height : size . ImageHeight ) } \" media=\" ({ ( _globalSettings . OurImg . MobileFirst ? $ "min-width: { minWidth } " : $ "max-width: { minWidth - 1 } ") } px)\" width=\" { size . ImageWidth } \" height=\" { size . ImageHeight } \" />") ;
376
+ }
377
+ else
378
+ {
379
+ sb . AppendLine ( $ "<source { ( jsLazyLoad ? "data-" : "" ) } srcset=\" { MediaItem . GetCropUrl ( width : size . ImageWidth ) } \" media=\" ({ ( _globalSettings . OurImg . MobileFirst ? $ "min-width: { minWidth } " : $ "max-width: { minWidth - 1 } ") } px)\" width=\" { size . ImageWidth } \" />") ;
380
+ }
381
+ }
355
382
}
356
383
357
384
if ( ! string . IsNullOrEmpty ( FileSource ) && ImgWidth > 0 && ImgHeight > 0 )
358
385
{
359
386
sourceHeight = size . ImageHeight > 0 ? size . ImageHeight : ( ImgHeight / ImgWidth ) * size . ImageWidth ;
360
- var sourceUrl = AddQueryToUrl ( FileSource , "width" , size . ImageWidth . ToString ( ) ) ;
387
+ var sourceUrl = AddQueryToUrl ( FileSource , "width" , size . ImageWidth . ToString ( ) ) + "&height=" + size . ImageHeight ;
361
388
sb . AppendLine ( $ "<source { ( jsLazyLoad ? "data-" : "" ) } srcset=\" { sourceUrl } \" media=\" ({ ( _globalSettings . OurImg . MobileFirst ? $ "min-width: { minWidth } " : $ "max-width: { minWidth - 1 } ") } px)\" width=\" { size . ImageWidth } \" { ( sourceHeight > 0 ? $ " height=\" { sourceHeight } \" " : "" ) } />") ;
362
389
363
390
}
@@ -456,23 +483,23 @@ private List<OurImageSize> GetImageSizes(bool isMedia = true)
456
483
457
484
if ( ImgWidthSmall > 0 )
458
485
{
459
- imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . Small , ImgWidthSmall , ImgCropAliasSmall ) : new OurImageSize ( Enums . OurScreenSize . Small , ImgWidthSmall , ImgHeightSmall ) ) ;
486
+ imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . Small , ImgWidthSmall , ImgHeightSmall , ImgCropAliasSmall ) : new OurImageSize ( Enums . OurScreenSize . Small , ImgWidthSmall , ImgHeightSmall ) ) ;
460
487
}
461
488
if ( ImgWidthMedium > 0 )
462
489
{
463
- imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . Medium , ImgWidthMedium , ImgCropAliasMedium ) : new OurImageSize ( Enums . OurScreenSize . Medium , ImgWidthMedium , ImgHeightMedium ) ) ;
490
+ imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . Medium , ImgWidthMedium , ImgHeightMedium , ImgCropAliasMedium ) : new OurImageSize ( Enums . OurScreenSize . Medium , ImgWidthMedium , ImgHeightMedium ) ) ;
464
491
}
465
492
if ( ImgWidthLarge > 0 )
466
493
{
467
- imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . Large , ImgWidthLarge , ImgCropAliasLarge ) : new OurImageSize ( Enums . OurScreenSize . Large , ImgWidthLarge , ImgHeightLarge ) ) ;
494
+ imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . Large , ImgWidthLarge , ImgHeightLarge , ImgCropAliasLarge ) : new OurImageSize ( Enums . OurScreenSize . Large , ImgWidthLarge , ImgHeightLarge ) ) ;
468
495
}
469
496
if ( ImgWidthExtraLarge > 0 )
470
497
{
471
- imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . ExtraLarge , ImgWidthExtraLarge , ImgCropAliasExtraLarge ) : new OurImageSize ( Enums . OurScreenSize . ExtraLarge , ImgWidthExtraLarge , ImgHeightExtraLarge ) ) ;
498
+ imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . ExtraLarge , ImgWidthExtraLarge , ImgHeightExtraLarge , ImgCropAliasExtraLarge ) : new OurImageSize ( Enums . OurScreenSize . ExtraLarge , ImgWidthExtraLarge , ImgHeightExtraLarge ) ) ;
472
499
}
473
500
if ( ImgWidthExtraExtraLarge > 0 )
474
501
{
475
- imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . ExtraExtraLarge , ImgWidthExtraExtraLarge , ImgCropAliasExtraExtraLarge ) : new OurImageSize ( Enums . OurScreenSize . ExtraExtraLarge , ImgWidthExtraExtraLarge , ImgHeightExtraExtraLarge ) ) ;
502
+ imageSizes . Add ( isMedia ? new OurImageSize ( Enums . OurScreenSize . ExtraExtraLarge , ImgWidthExtraExtraLarge , ImgHeightExtraExtraLarge , ImgCropAliasExtraExtraLarge ) : new OurImageSize ( Enums . OurScreenSize . ExtraExtraLarge , ImgWidthExtraExtraLarge , ImgHeightExtraExtraLarge ) ) ;
476
503
}
477
504
478
505
return imageSizes ;
0 commit comments