-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add autoPad resize action * Remove unneccessary model * Rename test case * Lint fixes
- Loading branch information
1 parent
1cd3594
commit bd8dc9a
Showing
7 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {Transformation} from "../../../../src"; | ||
import {Resize, autoPad} from "../../../../src/actions/resize"; | ||
import {Background} from "../../../../src/qualifiers"; | ||
|
||
describe('Tests for Transformation Action -- Resize.autoPad', () => { | ||
it('Ensures it generates the right transformation', () => { | ||
const tx = new Transformation().resize(autoPad(250, 250)).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() | ||
.width(250) | ||
.height(250) | ||
.background(Background.color('red'))).toString(); | ||
expect(tx).toContain('b_red,c_auto_pad,g_auto,h_250,w_250'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {BackgroundQualifier} from "../../qualifiers/background/shared/base/BackgroundQualifier.js"; | ||
import {Qualifier} from "../../internal/qualifier/Qualifier.js"; | ||
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"; | ||
|
||
/** | ||
* @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. | ||
* @extends Actions.Resize.autoPad | ||
* @memberOf Actions.Resize | ||
* @see Visit {@link Actions.Resize| Resize} for examples | ||
*/ | ||
class ResizeAutoPadAction extends ResizeSimpleAction { | ||
constructor(cropType: string, cropWidth: number | string, cropHeight?: number | string) { | ||
super(cropType, cropWidth, cropHeight); | ||
|
||
this.addQualifier(new Qualifier('g', 'auto')); | ||
} | ||
|
||
/** | ||
* @description Sets the background. | ||
* @param {Qualifiers.Background} backgroundQualifier Defines the background color to use instead of | ||
* transparent background areas or when resizing with padding. | ||
*/ | ||
background(backgroundQualifier: BackgroundQualifier | string): this { | ||
this._actionModel.background = createBackgroundModel(backgroundQualifier); | ||
return this.addQualifier(backgroundQualifier); | ||
} | ||
|
||
static fromJson(actionModel: IActionModel): ResizeAutoPadAction { | ||
const result = super.fromJson.apply(this, [actionModel]); | ||
actionModel.background && result.background(createBackgroundFromModel(actionModel.background as IBackgroundModel)); | ||
|
||
return result; | ||
} | ||
} | ||
|
||
|
||
export {ResizeAutoPadAction}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters