@@ -76,38 +76,52 @@ class Widget extends Component {
7676 preload : [ 1 , 1 ]
7777 } ;
7878
79- const galleryItems = ( folderImages || images ) . map ( img => {
80- const { width, height } = img ;
81- const croppedSrc = imageLib . cropImage ( img . src , {
82- width,
83- height,
84- disablePixelRatio : true
85- } ) ;
86- const msrc = imageLib . cropImage ( img . src , {
87- width : width / 2 ,
88- height : height / 2 ,
89- compression : 20 ,
90- disablePixelRatio : true
79+ const dimensionsTestPromises = ( folderImages || images ) . map ( img => new Promise ( resolve => {
80+ if ( img . width < 5 || img . height < 5 ) {
81+ const image = new Image ( ) ;
82+ image . onload = ( ) => resolve ( { width : image . naturalWidth , height : image . naturalHeight } ) ;
83+ image . src = img . src ;
84+ image . originalSrc = img . src ;
85+ } else {
86+ resolve ( { width : img . width , height : img . height } ) ;
87+ }
88+ } ) )
89+
90+ Promise . all ( dimensionsTestPromises )
91+ . then ( dimensions => {
92+ const galleryItems = ( folderImages || images ) . map ( ( img , index ) => {
93+ const { width, height } = dimensions [ index ] ? dimensions [ index ] : img ;
94+ const croppedSrc = imageLib . cropImage ( img . src , {
95+ width,
96+ height,
97+ disablePixelRatio : true
98+ } ) ;
99+ const msrc = imageLib . cropImage ( img . src , {
100+ width : width / 2 ,
101+ height : height / 2 ,
102+ compression : 20 ,
103+ disablePixelRatio : true
104+ } ) ;
105+
106+ return {
107+ src : croppedSrc ,
108+ sourceImg : img . src ,
109+ msrc,
110+ w : width ,
111+ h : height
112+ } ;
113+ } ) ;
114+ this . gallery = new PhotoSwipe ( pswpEle , photoSwipeUIdefault , galleryItems , options ) ;
115+ this . gallery . init ( ) ;
116+
117+ this . setState ( ( ) => ( { pswpOpen : true } ) ) ;
118+
119+ this . gallery . listen ( 'close' , ( ) => {
120+ spinner . hide ( ) ;
121+ this . setState ( ( ) => ( { pswpOpen : false } ) ) ;
122+ } ) ;
123+ this . gallery . listen ( 'imageLoadComplete' , ( ) => spinner . hide ( ) ) ;
91124 } ) ;
92-
93- return {
94- src : croppedSrc ,
95- sourceImg : img . src ,
96- msrc,
97- w : width ,
98- h : height
99- } ;
100- } ) ;
101- this . gallery = new PhotoSwipe ( pswpEle , photoSwipeUIdefault , galleryItems , options ) ;
102- this . gallery . init ( ) ;
103-
104- this . setState ( ( ) => ( { pswpOpen : true } ) ) ;
105-
106- this . gallery . listen ( 'close' , ( ) => {
107- spinner . hide ( ) ;
108- this . setState ( ( ) => ( { pswpOpen : false } ) ) ;
109- } ) ;
110- this . gallery . listen ( 'imageLoadComplete' , ( ) => spinner . hide ( ) ) ;
111125 } ;
112126
113127 shareImage = ( ) => {
0 commit comments