File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed
svelte-cloudinary/src/lib/components Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change 70
70
<Image
71
71
{...imageProps }
72
72
cdn =" cloudinary"
73
- transformer ={({ width , url , height }) => {
74
- return getCldImageUrl ( {
73
+ transformer ={({ width }) => {
74
+ const options = {
75
75
... imageProps ,
76
76
... cldOptions ,
77
- width ,
78
- height ,
79
- // @ts-ignore
80
- src: url
81
- })}
82
- }
77
+ // Without, get a "never" type error on options.width
78
+ width: imageProps .width
79
+ }
80
+
81
+ options .width = typeof options .width === ' string' ? parseInt (options .width ) : options .width ;
82
+ options .height = typeof options .height === ' string' ? parseInt (options .height ) : options .height ;
83
+
84
+ // The transformer options are used to create dynamic sizing when working with responsive images
85
+ // so these should override the default options collected from the props alone if
86
+ // the results are different.
87
+
88
+ if ( typeof width === ' number' && typeof options .width === ' number' && width !== options .width ) {
89
+ options .widthResize = width ;
90
+ }
91
+
92
+ return getCldImageUrl (options );
93
+ }}
83
94
/>
You can’t perform that action at this time.
0 commit comments