Proposal: image.slice(x, y, width, height) to slice parts of images

Hey everyone!
A recent pain I've been having dealing with the Image type in js is that I'm constantly working with spritesheets, and I would like to get a slice of an image without drawing it on screen.

Searching for a solution online was hopeless, as the main suggestion was to create a canvas HTML element as buffer, draw the part of the image I want on it and then extract the image from the canvas element. This is painful and there needs to be an alternative.

This is why I am proposing we add a slice method (name not definitive) and want to see the communities opinion on this suggestion.

Thank you!

Image is in HTML, and this discourse is for the JS language (which doesn't include HTML).

As for the name "slice", that already has an established meaning on lists of things as "produce a sub-list", ie strings, arrays, typed arrays, etc, so it probably isn't a good name for images.

1 Like

oh i misunderstood, sorry!