Skip to content

Commit

Permalink
Added isOpaque to MagickImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Nov 1, 2023
1 parent 4086e75 commit e679d6d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export interface IMagickImage extends IDisposable {
readonly height: number;
interpolate: PixelInterpolateMethod;
readonly interlace: Interlace;

/**
* Gets a value indicating whether none of the pixels in the image have an alpha value other
* than OpaqueAlpha (QuantumRange).
*/
readonly isOpaque: boolean;

label: string | null;
orientation: OrientationType;
page: MagickGeometry;
Expand Down Expand Up @@ -509,6 +516,12 @@ export class MagickImage extends NativeInstance implements IMagickImage {

get interlace(): Interlace { return ImageMagick._api._MagickImage_Interlace_Get(this._instance); }

get isOpaque(): boolean {
return Exception.usePointer(exception => {
return this.toBool(ImageMagick._api._MagickImage_IsOpaque_Get(this._instance, exception));
});
}

get interpolate(): PixelInterpolateMethod { return ImageMagick._api._MagickImage_Interpolate_Get(this._instance); }
set interpolate(value: PixelInterpolateMethod) { ImageMagick._api._MagickImage_Interpolate_Set(this._instance, value); }

Expand Down
18 changes: 18 additions & 0 deletions tests/magick-image/is-opaque.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { TestImages } from '@test/test-images';

describe('MagickImage#hasAlpha', () => {
it('should return true when the image is fully opaque', async () => {
TestImages.imageMagickJpg.use(image => {
expect(image.isOpaque).toBe(true);
});
});

it('should return false when the image contains a (semi) transparent pixel', async () => {
TestImages.redPng.use(image => {
expect(image.isOpaque).toBe(false);
});
});
});

0 comments on commit e679d6d

Please sign in to comment.