From d570bd8753422fb51837eda9f00c5e2c92fd369d Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sat, 5 Oct 2024 13:50:54 +0200 Subject: [PATCH] Added syncImageWithExifProfile to the MagickReadSettings. --- src/settings/magick-read-settings.ts | 16 ++++++++++ src/settings/magick-settings.ts | 6 ++-- .../sync-image-with-exif-profile.spec.ts | 29 +++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/settings/magick-read-settings/sync-image-with-exif-profile.spec.ts diff --git a/src/settings/magick-read-settings.ts b/src/settings/magick-read-settings.ts index 0071e9bd..59e8a855 100644 --- a/src/settings/magick-read-settings.ts +++ b/src/settings/magick-read-settings.ts @@ -41,6 +41,22 @@ export class MagickReadSettings extends MagickSettings { */ height?: number; + /** + * Gets or sets a value indicating whether the exif profile should be used to update + * some of the properties of the image (e.g. {@link MagickImage#density}, + * {@link MagickImage#orientation}). + */ + get syncImageWithExifProfile(): boolean { + const value = this.getDefine('exif:sync-image'); + if (value === null) + return true; + + return value.toLowerCase() === 'true'; + } + set syncImageWithExifProfile(value: boolean) { + this.setDefine('exif:sync-image', value.toString()); + } + /** * Gets or sets the width. */ diff --git a/src/settings/magick-settings.ts b/src/settings/magick-settings.ts index d97d7c8f..7b58a947 100644 --- a/src/settings/magick-settings.ts +++ b/src/settings/magick-settings.ts @@ -120,14 +120,14 @@ export class MagickSettings { * Returns the value of a format-specific option. * @param name The name of the option. */ - getDefine(name: string): string; + getDefine(name: string): string | null; /** * Returns the value of a format-specific option. * @param format The format to use. * @param name The name of the option. */ - getDefine(format: MagickFormat, name: string): string; - getDefine(nameOrFormat: MagickFormat | string, name?: string): string { + getDefine(format: MagickFormat, name: string): string | null; + getDefine(nameOrFormat: MagickFormat | string, name?: string): string | null { if (name !== undefined) return this._options[`${nameOrFormat}:${name}`] ?? null; diff --git a/tests/settings/magick-read-settings/sync-image-with-exif-profile.spec.ts b/tests/settings/magick-read-settings/sync-image-with-exif-profile.spec.ts new file mode 100644 index 00000000..81def78a --- /dev/null +++ b/tests/settings/magick-read-settings/sync-image-with-exif-profile.spec.ts @@ -0,0 +1,29 @@ +/* + Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. + Licensed under the Apache License, Version 2.0. +*/ + +import { MagickReadSettings } from '@src/settings/magick-read-settings'; + +describe('MagickReadSettings#syncImageWithExifProfile', () => { + it('should return true as the default value', () => { + const settings = new MagickReadSettings(); + + expect(settings.syncImageWithExifProfile).toBe(true); + }); + + it('should not set the define when the value is not set', () => { + const settings = new MagickReadSettings(); + const value = settings.getDefine('exif:sync-image'); + + expect(value).toBeNull(); + }); + + it('should change the image option', () => { + const settings = new MagickReadSettings(); + settings.syncImageWithExifProfile = false; + + const value = settings.getDefine('exif:sync-image'); + expect(value).toBe('false'); + }); +});