Skip to content

Support for converting all images to a certain type #206

@nart4hire

Description

@nart4hire

What problem does this feature solve?

Basically to convert every image to webp (certain SEO use cases) or avif with cleaner and more practical code:
You can write:

conversion: [
  { from: '*', to: 'webp' },
  { from: 'JPG', to: 'jpeg' },
],

Instead of:

conversion: [
  { from: 'jpeg', to: 'webp' },
  { from: 'png', to: 'webp' },
  ... // All the other formats you use
  { from: 'JPG', to: 'jpeg' },
],

Not really integral, but nice to have, down to make the pr if approved.

What does the proposed API look like?

So, right now it matches the exact extension:

const userConversion = this.options.conversion.find(
  (item) => item.from === ext,
);

You can also afterwards check whether or not there is a *

const userConversion = this.options.conversion.find(
  (item) => item.from === ext,
) ?? this.options.conversion.find(
  (item) => item.from === '*',
);

Or, you could also make a matcher map on creation of the ImageProcessor object, but since there aren't realistically a large abundance of options, id say that an extra find call is fine for performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions