Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic resizing of images #31

Open
2 tasks done
grzracz opened this issue Nov 24, 2023 · 4 comments
Open
2 tasks done

Automatic resizing of images #31

grzracz opened this issue Nov 24, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@grzracz
Copy link

grzracz commented Nov 24, 2023

Describe the feature you'd like to request

It would be useful to based on the file extension or folder structure decide what is the max resolution for each file.
For example, some of my icons are 1024x1024 but that size is unnecessary in production, so it would be nice to before optimization reduce their size to 256x256 and then optimize. Keeping the aspect ratio should not break anything (and it would be optional anyway).

Describe the solution you'd like

An entry in config that helps with resizing the images based on extension or folder structure.

Additional context

No response

Validations

  • Read the docs.
  • Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.
@grzracz grzracz added the enhancement New feature or request label Nov 24, 2023
@maxswjeon
Copy link

Yes! In addition, support for srcset would be really good if possible!

@IgorSzymanski
Copy link

I was thinking about doing it by passing parameters as query.
Let's say we want to perform this operation on the image:

sharp('input.jpg')
  .resize({
     width: 30,
     height: 30,
     position: 'right top',
     fit: 'contain',
  })
  .gamma(2.2, 3.0)

We could use an object to represent what we want to do with the image (or an array if the order is that relevant).

{
    "resize": {
    	"width": 30,
        "height": 30,
        "position": "right top",
      	"fit": "contain"
    },
    "gamma": [2.2, 3.0]
}

And pass it as query.

const image = import('input.jpg?resize[width]=30&resize[height]=30&resize[position]=right%20top&resize[fit]=contain&gamma[]=2.2&gamma[]=3')

It looks tedious, but this could be wrapped and handled nicely by a component.

Not sure how good this idea is as this is not my field of expertise.

@menasheh
Copy link

this would be awesome

@alexanderhorner
Copy link

Sounds exactly like this package: https://www.npmjs.com/package/vite-imagetools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants