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

image.hasAlpha() Method? #271

Closed
MCTaylor17 opened this issue May 12, 2017 · 4 comments · Fixed by #585
Closed

image.hasAlpha() Method? #271

MCTaylor17 opened this issue May 12, 2017 · 4 comments · Fixed by #585
Assignees
Labels
enhancement a request for a new feature or change in behavior

Comments

@MCTaylor17
Copy link

MCTaylor17 commented May 12, 2017

Is it possible to add a method for determining if a PNG has a transparency colour channel?

Creating alpha channels when none is required results in unnecessarily large images.

Ideally, the following could be used:

image.rgba( image.hasAlpha() );

This would either preserve the channel when used remove it when unecessary.

Alternatively you could use it to determine file types:

if ( image.hasAlpha() ) {
    file = "filename.png";
} else {
    file = "filename.jpg";
}
@oliver-moran
Copy link
Collaborator

For PNG images, you can save with an alpha channel or not using:

image.rgba(false).write("image-no-alpha.png");

Or is it that you want to detect of there are any non-opaque pixels and decide to save as a JPEG if there are none?

@iwsfg
Copy link
Contributor

iwsfg commented May 28, 2017

Or is it that you want to detect of there are any non-opaque pixels and decide to save as a JPEG if there are none?

This.

Seems like a good idea, I'll implement it this tomorrow.

@iwsfg iwsfg self-assigned this May 28, 2017
@nickgrealy
Copy link

How's this going? Looking forward to this feature!

@hipstersmoothie
Copy link
Collaborator

Released in v0.4.0

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

Successfully merging a pull request may close this issue.

5 participants