Skip to content

Commit

Permalink
Added syncImageWithExifProfile to the MagickReadSettings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Oct 5, 2024
1 parent 23e5eac commit d570bd8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/settings/magick-read-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/settings/magick-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit d570bd8

Please sign in to comment.