Skip to content

Commit 85eb36c

Browse files
matmenclaude
andcommitted
options objects for roundCorners and fisheye
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MLHc7GW46D6BmwtEM2khgr
1 parent c6bf4d1 commit 85eb36c

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎src/image.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ export interface EncodeOptions {
8888
metadata?: Metadata;
8989
}
9090

91+
/** Options of {@link Image.roundCorners} */
92+
export interface RoundCornersOptions {
93+
/** The radius of the corners. Default: a quarter of the smaller side */
94+
radius?: number;
95+
}
96+
97+
/** Options of {@link Image.fisheye} */
98+
export interface FisheyeOptions {
99+
/** The distortion strength (exponent of the radial mapping), higher values bulge the center more. Default: `2` */
100+
strength?: number;
101+
}
102+
91103
/** Options of {@link Image.renderSVG} */
92104
export interface SVGOptions {
93105
/** The scale, or the width or height in pixels, see `mode`. Default: `1` */
@@ -1648,11 +1660,18 @@ export class Image {
16481660
};
16491661
}
16501662

1663+
/**
1664+
* Rounds the images corners, with antialiased edges
1665+
* @param options See {@link RoundCornersOptions}
1666+
*/
1667+
roundCorners(options?: RoundCornersOptions): this;
16511668
/**
16521669
* Rounds the images corners, with antialiased edges
16531670
* @param [radius=min(width,height)/4] The radius of the corners
16541671
*/
1655-
roundCorners(radius: number = Math.min(this.width, this.height) / 4): this {
1672+
roundCorners(radius?: number): this;
1673+
roundCorners(radiusOrOptions?: number | RoundCornersOptions): this {
1674+
let radius = (isOptions(radiusOrOptions) ? radiusOrOptions.radius : radiusOrOptions) ?? Math.min(this.width, this.height) / 4;
16561675
radius = Math.max(0, Math.min(radius, this.width / 2, this.height / 2));
16571676
const size = Math.ceil(radius);
16581677

@@ -1694,11 +1713,18 @@ export class Image {
16941713
};
16951714
}
16961715

1716+
/**
1717+
* Applies a fisheye (barrel distortion) effect
1718+
* @param options See {@link FisheyeOptions}
1719+
*/
1720+
fisheye(options?: FisheyeOptions): this;
16971721
/**
16981722
* Applies a fisheye (barrel distortion) effect
16991723
* @param [strength=2] The distortion strength (exponent of the radial mapping), higher values bulge the center more
17001724
*/
1701-
fisheye(strength = 2): this {
1725+
fisheye(strength?: number): this;
1726+
fisheye(strengthOrOptions?: number | FisheyeOptions): this {
1727+
const strength = (isOptions(strengthOrOptions) ? strengthOrOptions.strength : strengthOrOptions) ?? 2;
17021728
const r = new Image(this.width, this.height);
17031729

17041730
const w = this.width;

‎src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { view } from './util/mem.ts';
88
import { ImageType } from './image-type.ts';
99

1010
export { Image } from './image.ts';
11-
export type { Color, ColorFunction, ResizeMode, SVGScaleMode, PNGMetadata, TextStyle, DecodeOptions, CompositeOptions, BlendMode, CropCircleOptions, DominantColorOptions, RotateOptions, ColorToAlphaOptions, ResizeOptions, AdjustOptions, SharpenOptions, PNGEncodeOptions, JPEGEncodeOptions, EncodeOptions, SVGOptions, TextOptions } from './image.ts';
11+
export type { Color, ColorFunction, ResizeMode, SVGScaleMode, PNGMetadata, TextStyle, DecodeOptions, CompositeOptions, BlendMode, CropCircleOptions, DominantColorOptions, RotateOptions, ColorToAlphaOptions, ResizeOptions, AdjustOptions, SharpenOptions, PNGEncodeOptions, JPEGEncodeOptions, EncodeOptions, SVGOptions, TextOptions, RoundCornersOptions, FisheyeOptions } from './image.ts';
1212
export { Frame } from './frame.ts';
1313
export type { FrameDisposalModeName, FrameDisposalModeId, FrameOptions } from './frame.ts';
1414
export { GIF } from './gif.ts';

‎tests/options.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const same = (name, a, b) => {
3131
same('composite', tile().composite(logo, 5, 7, {opacity: 0.5, mode: 'multiply'}), tile().composite(logo, {x: 5, y: 7, opacity: 0.5, mode: 'multiply'}));
3232
same('composite default', tile().composite(logo), tile().composite(logo, {}));
3333
same('sharpen', tile().sharpen(2, 3), tile().sharpen({amount: 2, radius: 3}));
34+
same('roundCorners', tile().roundCorners(9), tile().roundCorners({radius: 9}));
35+
same('roundCorners default', tile().roundCorners(), tile().roundCorners({}));
36+
same('fisheye', tile().fisheye(3), tile().fisheye({strength: 3}));
37+
same('fisheye default', tile().fisheye(), tile().fisheye({}));
3438

3539
// encoders: decoded, since the metadata has a creation time
3640
const pixelsOf = async data => (await Image.decode(data)).bitmap;

0 commit comments

Comments
 (0)