Skip to content

Commit 066ceec

Browse files
committed
resizing after transformations for responsive
1 parent fcd1077 commit 066ceec

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

svelte-cloudinary/src/lib/components/CldImage.svelte

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,25 @@
7070
<Image
7171
{...imageProps}
7272
cdn="cloudinary"
73-
transformer={({ width, url, height}) => {
74-
return getCldImageUrl({
73+
transformer={({ width }) => {
74+
const options = {
7575
...imageProps,
7676
...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+
}}
8394
/>

0 commit comments

Comments
 (0)