Skip to content

Commit

Permalink
Added hasProfile to MagickImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Nov 26, 2024
1 parent 5ad4af4 commit 7093be7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,12 @@ export interface IMagickImage extends IDisposable {
*/
grayscale(method: PixelIntensityMethod): void;

/**
* Gets a value indicating whether a profile with the specified name already exists on the image.
* @param name The name of the profile.
*/
hasProfile(name: string): boolean;

/**
* Creates a color histogram.
*/
Expand Down Expand Up @@ -2830,6 +2836,12 @@ export class MagickImage extends NativeInstance implements IMagickImage {
});
}

hasProfile(name: string): boolean {
return _withString(name, namePtr => {
return this.toBool(ImageMagick._api._MagickImage_HasProfile(this._instance, namePtr));
});
}

histogram(): Map<string, number> {
const result = new Map<string, number>();

Expand Down
28 changes: 28 additions & 0 deletions tests/magick-image/has-profile.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
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#hasProfile', () => {
it('should return true when image contains a profile with the specified name', () => {
TestImages.fujiFilmFinePixS1ProJpg.use(image => {
image.profileNames.forEach(name => {
expect(image.hasProfile(name)).toBeTruthy();
});
});
});

it('should return false when image does not contain a profile with the specified name', () => {
TestImages.imageMagickJpg.use(image => {
expect(image.hasProfile('foobar')).toBeFalsy();

expect(image.hasProfile('8bim')).toBeFalsy();
expect(image.hasProfile('exif')).toBeFalsy();
expect(image.hasProfile('icc')).toBeFalsy();
expect(image.hasProfile('iptc')).toBeFalsy();
expect(image.hasProfile('xmp')).toBeFalsy();
});
});
});

0 comments on commit 7093be7

Please sign in to comment.