image-actions icon indicating copy to clipboard operation
image-actions copied to clipboard

feat: add support for resizing images

Open jyash97 opened this issue 3 years ago • 6 comments

👋🏻 Hi there!

Adds a new field size which accepts glob patterns and defines custom width and height for the same. This can be used to target specific image or multiple images residing under a directory.

Now in config if someone adds below config:

size: {
      "*/**/__tests__/test-images": { width: 200, height: 100 },
      "*/**/__tests__/test-images/icon.png": { width: 200, }
    }

All the files matching the glob would be resized. This can be used to target specific files, same extension files and files under a specific directory. Both width and height can be passed or either of the things can be passed. If empty object is passed it wont resize the file.

Note This is done using sharp method resize which have few default configs. So for eg: if width and height are defined it crops the image as the default fit value is cover. Read more here: https://sharp.pixelplumbing.com/api-resize#resize


What does this PR introduce?

In a few bullet points, please describe the changes this Pull Request makes. E.g.:

  • adds resizing support
  • [ ] TODO readme update

Related issues

Closes #20 #60

Testing steps

Test 1

 size: {
      "*/**/__tests__/test-images": { width: 200, height: 100 },
}

All the files was resized.

Test 2

size: {
      "*/**/__tests__/test-images/icon.png": { width: 200 },
}

Only icon image was resized.

cc @benschwarz @mikedijkstra

jyash97 avatar May 02 '21 14:05 jyash97

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 02 '21 14:05 CLAassistant

@benschwarz any chance of getting this merged?

AndreasMadsen avatar Oct 19 '21 16:10 AndreasMadsen

This would be really nice to have

Stanzilla avatar Feb 03 '22 00:02 Stanzilla

please merge, this is great.

risograph avatar May 02 '23 16:05 risograph

@benschwarz Could this please be reviewed/merged?

mschfh avatar Jan 22 '24 17:01 mschfh

@benschwarz This would be useful to me as well! looking forward to the merge

K-J-Q avatar Feb 15 '24 02:02 K-J-Q