@@ -122,7 +122,7 @@ private function getImageHtmlFromImage(DOMElement $image, string $html): string
122122 return '' ;
123123 }
124124
125- $ regex = '/<img ' .self ::MARKER_CODE .'=" ' .$ imageMarker .'"([^>"]*)(?:"[^"]*"[^>"]*)* >/ ' ;
125+ $ regex = '/<img ' .self ::MARKER_CODE .'=" ' .$ imageMarker .'"([^\>]+) >/ ' ;
126126 if (!preg_match ($ regex , $ html , $ imageHtmlMatch )) {
127127 return '' ;
128128 }
@@ -145,15 +145,35 @@ private function getPictureHtmlFromImage(DOMElement $image, string $html): strin
145145 if (!$ this ->isAllowedByParentNode ($ image )) {
146146 return '' ;
147147 }
148+
149+ $ imageSrcSet = $ image ->getAttribute ('srcset ' );
150+ if ($ imageSrcSet ) {
151+ $ srcSetImages = explode (', ' , $ imageSrcSet );
152+ $ imageUrls = [];
153+ foreach ($ srcSetImages as $ srcSetImage ) {
154+ $ pieces = explode (' ' , trim ($ srcSetImage ));
155+ if (isset ($ pieces [1 ])) {
156+ $ descriptor = $ pieces [1 ];
157+ $ imageUrls [$ descriptor ] = $ pieces [0 ];
158+ } else {
159+ $ descriptor = 0 ;
160+ $ imageUrl = $ imageUrls [$ descriptor ] = $ pieces [0 ];
161+ }
162+ }
163+ $ images = $ this ->imageCollector ->collect ($ imageUrls );
164+ if (!count ($ images ) > 0 ) {
165+ return '' ;
166+ }
167+ } else {
168+ $ imageUrl = $ this ->getImageUrlFromElement ($ image );
169+ if (!$ this ->isAllowedByImageUrl ($ imageUrl )) {
170+ return '' ;
171+ }
148172
149- $ imageUrl = $ this ->getImageUrlFromElement ($ image );
150- if (!$ this ->isAllowedByImageUrl ($ imageUrl )) {
151- return '' ;
152- }
153-
154- $ images = $ this ->imageCollector ->collect ($ imageUrl );
155- if (!count ($ images ) > 0 ) {
156- return '' ;
173+ $ images = $ this ->imageCollector ->collect ($ imageUrl );
174+ if (!count ($ images ) > 0 ) {
175+ return '' ;
176+ }
157177 }
158178
159179 $ imageHtml = $ this ->getImageHtmlFromImage ($ image , $ html );
@@ -280,6 +300,7 @@ private function replaceInlineCssBackgroundImages(string $html): string
280300 private function getImageUrlFromElement (DOMElement $ image ): string
281301 {
282302 $ attributes = $ this ->getAllowedSrcAttributes ();
303+
283304 $ imageUrl = '' ;
284305 foreach ($ attributes as $ attribute ) {
285306 $ imageUrl = $ image ->getAttribute ($ attribute );
0 commit comments