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

new Image(width, height) or new image({width, height}) ? #322

Open
lpatiny opened this issue May 5, 2023 · 3 comments
Open

new Image(width, height) or new image({width, height}) ? #322

lpatiny opened this issue May 5, 2023 · 3 comments

Comments

@lpatiny
Copy link
Member

lpatiny commented May 5, 2023

Currently when creating a new Image the 2 first arguments are width and height.

Would it make sense to have rather width and height as mandatory parameter of the 'options' and have only one arguments ?

This would allow to simplify the 'decode' code like in:

https://github.com/image-js/image-js-typescript/blob/main/src/load/decodeJpeg.ts#LL17C1-L20C6

But also allow the following code (useful when sending an image to a webworker):

const rawImage = image.getRawImage();

const image2 = new Image(rawImage);

@targos WDTY

@targos
Copy link
Member

targos commented May 5, 2023

SGTM.

Be careful with new Image(rawImage). It will only work with 8-bit RGBA images.

@lpatiny
Copy link
Member Author

lpatiny commented May 10, 2023

Is there a specific reason that we didn't return the image kind in getRawImage ?

return {
width: this.width,
height: this.height,
data: this.data,
channels: this.channels,
bitDepth: this.bitDepth,
};

The idea was actually also to return the kind so that we can always use new Image(rawImage)

@targos
Copy link
Member

targos commented May 10, 2023

There is no idea in this function. It's there as a workaround for some algorithms and shouldn't be used from other projects.

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

No branches or pull requests

2 participants