Skip to content

Commit 6b9b472

Browse files
atcastledylhunn
authored andcommitted
fix(common): Don't warn about image distortion is fill mode is enabled (#47824)
The image distortion warning (when rendered aspect ratio is noticeably different than intrinsic) doesn't make sense with fill mode, where the user may want the image to stretch, crop or letterbox. PR Close #47824
1 parent 883b32c commit 6b9b472

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,11 @@ export class NgOptimizedImage implements OnInit, OnChanges, OnDestroy {
367367
assertEmptyWidthAndHeight(this);
368368
} else {
369369
assertNonEmptyWidthAndHeight(this);
370+
// Only check for distorted images when not in fill mode, where
371+
// images may be intentionally stretched, cropped or letterboxed.
372+
assertNoImageDistortion(this, this.imgElement, this.renderer);
370373
}
371374
assertValidLoadingInput(this);
372-
assertNoImageDistortion(this, this.imgElement, this.renderer);
373375
if (!this.ngSrcset) {
374376
assertNoComplexSizes(this);
375377
}

packages/core/test/bundling/image-directive/e2e/image-distortion/image-distortion.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ import {Component} from '@angular/core';
3636
<!-- Aspect-ratio: 1.0652173913 -->
3737
<img ngSrc="/e2e/b.png" width="245" height="230">
3838
<br>
39+
<!-- Fill mode disables aspect ratio warning -->
40+
<!-- Aspect-ratio: 0.1 -->
41+
<img ngSrc="/e2e/b.png" width="24" height="240" disableOptimizedSrcset fill>
42+
<br>
3943
<!-- Supplied aspect ratio is correct & image has 0x0 rendered size -->
4044
<img ngSrc="/e2e/a.png" width="25" height="25" style="display: none">
4145
<br>

0 commit comments

Comments
 (0)