From 7093be724d669c5ee772477df47cdb48158d395f Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Tue, 26 Nov 2024 17:08:05 +0100 Subject: [PATCH] Added hasProfile to MagickImage. --- src/magick-image.ts | 12 +++++++++++ tests/magick-image/has-profile.spec.ts | 28 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/magick-image/has-profile.spec.ts diff --git a/src/magick-image.ts b/src/magick-image.ts index 6e71f86..c343c73 100644 --- a/src/magick-image.ts +++ b/src/magick-image.ts @@ -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. */ @@ -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 { const result = new Map(); diff --git a/tests/magick-image/has-profile.spec.ts b/tests/magick-image/has-profile.spec.ts new file mode 100644 index 0000000..af21273 --- /dev/null +++ b/tests/magick-image/has-profile.spec.ts @@ -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(); + }); + }); +});