@@ -109,15 +109,18 @@ public function findImageCandidate(
109
109
float $ density
110
110
): ?SourceSizeImageCandidateMatch {
111
111
112
- // Run through the source sizes
112
+ // Run through the source sizes (from biggest to smallest)
113
113
/** @var SourceSize $sourceSize */
114
114
$ lastMinimumWidth = null ;
115
115
foreach ($ this ->getArrayCopy () as $ sourceSize ) {
116
116
$ mediaCondition = $ sourceSize ->getMediaCondition ();
117
- if ($ mediaCondition ->matches ($ breakpoint , $ density )) {
117
+
118
+ // If the current breakpoint and density matches the source size condition
119
+ if ($ mediaCondition ->matches ($ breakpoint , $ density , $ lastMinimumWidth )) {
118
120
return $ this ->findImageCandidateForSourceSize (
119
121
$ sourceSize ,
120
122
$ imageCandidates ,
123
+ $ density ,
121
124
$ breakpoint ,
122
125
$ this ->getSourceSizeMaximumWidth ($ mediaCondition , $ lastMinimumWidth )
123
126
);
@@ -133,6 +136,7 @@ public function findImageCandidate(
133
136
*
134
137
* @param SourceSize $sourceSize Matching source size
135
138
* @param ImageCandidateSetInterface $imageCandidates Image candidates
139
+ * @param float $density Density
136
140
* @param AbsoluteLengthInterface $minWidth Minimum viewport width
137
141
* @param AbsoluteLengthInterface|null $maxWidth Maximum viewport width
138
142
*
@@ -141,6 +145,7 @@ public function findImageCandidate(
141
145
protected function findImageCandidateForSourceSize (
142
146
SourceSize $ sourceSize ,
143
147
ImageCandidateSetInterface $ imageCandidates ,
148
+ float $ density ,
144
149
AbsoluteLengthInterface $ minWidth ,
145
150
AbsoluteLengthInterface $ maxWidth = null
146
151
): ?SourceSizeImageCandidateMatch {
@@ -153,7 +158,7 @@ protected function findImageCandidateForSourceSize(
153
158
return $ this ->findImageCandidateForMinImageWidth (
154
159
$ sourceSize ,
155
160
$ imageCandidates ,
156
- max ($ sourceSize ->getValue ()->getValue ($ minWidth ), $ sourceSize ->getValue ()->getValue ($ maxWidth ))
161
+ max ($ sourceSize ->getValue ()->getValue ($ minWidth ), $ sourceSize ->getValue ()->getValue ($ maxWidth )) * $ density
157
162
);
158
163
}
159
164
0 commit comments