@@ -10,7 +10,7 @@ class ResponsiveImages extends Component
10
10
{
11
11
public $ imageName ;
12
12
13
- public $ imageExt ;
13
+ private $ imageExt ;
14
14
15
15
public $ imageWidth ;
16
16
@@ -27,21 +27,18 @@ class ResponsiveImages extends Component
27
27
private $ imagePath ;
28
28
29
29
public function __construct (
30
- $ imageName ,
31
- $ imageExt ,
32
- $ imageWidth ,
33
- $ imageHeight ,
34
- $ altText ,
30
+ $ image ,
31
+ $ imageWidth = '300 ' ,
32
+ $ imageHeight = '200 ' ,
33
+ $ altText = 'Alt text ' ,
35
34
$ loading = 'lazy ' ,
36
- $ class = 'w-full '
37
35
) {
38
- $ this ->imageName = $ imageName ;
39
- $ this ->imageExt = $ imageExt ;
36
+ $ this ->imageName = $ image ;
37
+ $ this ->imageExt = pathinfo ( $ this -> imagePath . $ this -> imageName , PATHINFO_EXTENSION ) ;
40
38
$ this ->imageWidth = $ imageWidth ;
41
39
$ this ->imageHeight = $ imageHeight ;
42
40
$ this ->altText = $ altText ;
43
41
$ this ->loading = $ loading ;
44
- $ this ->class = $ class ;
45
42
$ this ->imagePath = config ('responsive-images.image_path ' );
46
43
$ this ->dimensions = config ('responsive-images.dimensions ' );
47
44
}
@@ -51,18 +48,17 @@ public function render(): View|Closure|string
51
48
$ imageSet = [];
52
49
53
50
foreach ($ this ->dimensions as $ dimension ) {
54
- $ src = asset ($ this ->imagePath . $ this ->imageName . '- ' . $ dimension [0 ]. ' . ' . ' webp ' );
51
+ $ src = asset ($ this ->imagePath . pathinfo ( $ this ->imageName , PATHINFO_FILENAME ) . '- ' . $ dimension [0 ] . ' . webp ' );
55
52
$ descriptor = $ dimension [1 ].'w ' ;
56
53
$ imageSet [] = "{$ src } {$ descriptor }" ;
57
54
}
58
55
59
56
$ srcset = implode (', ' , $ imageSet );
60
57
61
58
return view ('fuelviews::responsive-images ' , [
62
- 'imgsrc ' => asset ($ this ->imagePath . $ this ->imageName . '- ' . $ this ->dimensions [1 ][0 ]. '. ' . $ this ->imageExt ),
59
+ 'imgsrc ' => asset ($ this ->imagePath . pathinfo ( $ this ->imageName , PATHINFO_FILENAME ) . '- ' . $ this ->dimensions [1 ][0 ] . '. ' . $ this ->imageExt ),
63
60
'srcset ' => $ srcset ,
64
61
'altText ' => $ this ->altText ,
65
- 'class ' => $ this ->class ,
66
62
'imageWidth ' => $ this ->imageWidth ,
67
63
'imageHeight ' => $ this ->imageHeight ,
68
64
'loading ' => $ this ->loading ,
0 commit comments