Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __TESTS__/unit/actions/Reshape.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ describe('Tests for Transformation Action -- Cutter', () => {

expect(url).toBe('e_distort:1:2:3:4:5:6:7:8');
});

it('Trims an image', () => {
const url = createNewImage()
.reshape(Reshape.trim().colorOverride('blue').colorSimilarity(15))
.toString();

expect(url).toBe('e_trim:15:blue');
});
});
15 changes: 13 additions & 2 deletions src/actions/reshape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ImageSource} from "../values/source/sourceTypes/ImageSource";
import {DistortArcAction} from "./reshape/DistortArc";
import {ShearAction} from "./reshape/Shear";
import {DistortAction, IDistortCoordinates} from "./reshape/Distort";
import {TrimAction} from "./reshape/TrimAction";

type IReshape = CutByImage | DistortArcAction;

Expand Down Expand Up @@ -59,5 +60,15 @@ function shear(): ShearAction {
return new ShearAction();
}

const Reshape = {cutByImage, distortArc, distort, shear};
export {cutByImage, Reshape, IReshape, distortArc, distort, shear};
/**
* @description Removes the edges of the image based on the color of the corner pixels.
* Specify a color other than the color of the corner pixels using the colorOverride() method
* @memberOf Actions.Reshape
* @return {Actions.Reshape.TrimAction}
*/
function trim(): TrimAction {
return new TrimAction();
}

const Reshape = {cutByImage, distortArc, distort, shear, trim};
export {cutByImage, Reshape, IReshape, distortArc, distort, shear, trim};
43 changes: 43 additions & 0 deletions src/actions/reshape/TrimAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {Action} from "../../internal/Action";
import {SystemColors} from "../../values/color";

/**
* @description Removes the edges of the image based on the color of the corner pixels.
* Specify a color other than the color of the corner pixels using the colorOverride() method
* @memberOf Actions.Reshape
* @extends {SDK.Action}
*/
class TrimAction extends Action {
private _tolerance: number;
private _color: SystemColors | string;

/**
* @param {number} tolerance The tolerance level for color similarity.
*/
colorSimilarity(tolerance: number): this {
this._tolerance = tolerance;
return this;
}

/**
* @param {string | Values.Color} color Overrides the corner pixels color with the specified color.
*/
colorOverride(color: SystemColors | string): this {
this._color = color;
return this;
}

toString(): string {
// image.reshape(Reshape.trim()->colorSimilarity(50)->colorOverride(Color.YELLOW));
// e_trim:50:yellow

return [
'e_trim',
this._tolerance,
this._color
].filter((a) => a).join(':');
}
}


export {TrimAction};