FatehAK / vite-plugin-image-optimizer

Optimize your image assets using Sharp.js and SVGO.
MIT License
307 stars 15 forks source link

Convert to different image formats #20

Open VictorCam opened 1 year ago

VictorCam commented 1 year ago

Describe the feature you'd like to request

It would be really great if you could convert an image into a different image formats for production

for example converting a png image into another format available in sharp like webp/avif/etc...

I think this would be great to save people the time when doing the conversion, and to save some additional space.

Describe the solution you'd like

maybe a toFormat option in the config file since that is the name of the method in the sharp package. Where you can specify as a string what format you would like to image to be converted to.

Additional context

https://sharp.pixelplumbing.com/api-output#toformat

Thank You!

Validations

FatehAK commented 1 year ago

Hey @VictorCam thank you for the suggestion, this is being looked at the PR raised by @netolicak. You can follow the progress https://github.com/FatehAK/vite-plugin-image-optimizer/pull/23

VictorCam commented 1 year ago

Sound good. Thank you!

tuber84 commented 1 year ago

An extremely necessary option.

sergey-yarchuk-4ib commented 11 months ago

I need that)

Maxou44 commented 6 months ago

It could be awesome if the plugin generates various outputs and automatically choose the best file at runtime based on file size and format.

  1. The plugin could generate automatically avif, webp, png and jpg (only if the pictures don't contains alpha channel)
  2. We remove useless file based on sizes and original file size (example: it's useless to keep a webp file if the png file is smaller / it's useless to keep "optimized" file if the original one is smaller)
  3. At runtime, we test the Avif and webp compatibility, based on these tests, we resolve the smallest file