Skip to content

Commit

Permalink
autoPad grvity fix (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
magdakwiecien authored Feb 22, 2024
1 parent 1d914c8 commit 72eefdb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions __TESTS__/unit/actions/Resize/AutoPadResizeAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ describe('Tests for Transformation Action -- Resize.autoPad', () => {
expect(tx).toContain('c_auto_pad,g_auto,h_250,w_250');
});

it('Ignores gravity and always returns g_auto', () => {
const tx = new Transformation().resize(autoPad(250, 250).gravity("north")).toString();
expect(tx).toContain('c_auto_pad,g_auto,h_250,w_250');
});

it('Ensures it generates the right transformation using qualifiers', () => {
const tx = new Transformation().resize(
Resize.autoPad()
Expand Down
7 changes: 7 additions & 0 deletions src/actions/resize/ResizeAutoPadAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {IActionModel} from "../../internal/models/IActionModel.js";
import {createBackgroundModel, IBackgroundModel} from "../../internal/models/createBackgroundModel.js";
import {createBackgroundFromModel} from "../../internal/models/createBackgroundFromModel.js";
import {ResizeSimpleAction} from "./ResizeSimpleAction.js";
import {IGravity} from "../../qualifiers/gravity/GravityQualifier.js";

/**
* @description Tries to prevent a "bad crop" by first attempting to use the auto cropping mode, but adding some padding if the algorithm determines that more of the original image needs to be included in the final image.
Expand All @@ -28,6 +29,12 @@ class ResizeAutoPadAction extends ResizeSimpleAction {
return this.addQualifier(backgroundQualifier);
}

gravity(gravity: IGravity): this {
// Only `auto` gravity is allowed (and required) for `c_auto_pad` and it's already added automatically in the constructor.
// Although, this method is needed to exist because it is being shown in autogenerated SDK code snippet.
return this;
}

static fromJson(actionModel: IActionModel): ResizeAutoPadAction {
const result = super.fromJson.apply(this, [actionModel]);
actionModel.background && result.background(createBackgroundFromModel(actionModel.background as IBackgroundModel));
Expand Down

0 comments on commit 72eefdb

Please sign in to comment.