kit icon indicating copy to clipboard operation
kit copied to clipboard

Allow passing imagetools parameters when dynamically importing images for enhanced:img

Open Extarys opened this issue 1 year ago • 0 comments
trafficstars

Describe the problem

Technically it is a bug, because it should work, but seeing the source code it was not implemented at all.

I'm looking for a way to set the quality of all images by default, and then crop and tint a dynamically some imported image. Obviously, this issue is geared toward having imagetools work for dynamic import first :).

To add to @flippbit list of things that doesn't work: (https://github.com/sveltejs/kit/issues/11535#issuecomment-1941956125)

import MyImage from './path/to/your/image.jpg?enhanced&quality=80&tint=#ffaa22';

Throw an error:

Cannot find module './path/to/your/image.jpg?enhanced&quality=80' or its corresponding type declarations.ts(2307)

Sidenote: Nuxt Img can have a global configuration to set default quality, etc: https://image.nuxt.com/get-started/configuration

*EDIT Thanks to a discord mod: It should be implemented and is a type error: https://github.com/JonasKruckenberg/imagetools/issues/160#issuecomment-965021959

sveltejs/enhanced-img type: https://github.com/sveltejs/kit/blob/6056ba30e29ac5747c356fbf1a42dd71f2c4aa1f/packages/enhanced-img/types/ambient.d.ts

Describe the proposed solution

Implement

import MyImage from './path/to/your/image.jpg?enhanced&quality=80&tint=#ffaa22';

Alternatives considered

Make enhanced:img accept a variable as src for loops.

Importance

i cannot use SvelteKit without it

Additional Information

Not having this is kind of a nightmare IMO when trying to optimize images as much as possible and when using components for almost everything (Hero banner, Section's background, Image loop, galleries, etc all must use dynamic import of the images if using enhanced:img.

I didn't find a way yet on how to use it with user uploaded content since it change the image at build time.

Extarys avatar Aug 24 '24 21:08 Extarys