Skip to content

Commit 7069fff

Browse files
committed
Fixed image methods.
1 parent 29aef32 commit 7069fff

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/canvas.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,12 @@ class CanvasConstructor {
219219
* @chainable
220220
*/
221221
addImage(buffer, x, y, width, height, options = {}) {
222+
this.save();
222223
if (options.type) {
223-
if (options.type === 'round') return this.addRoundImage(buffer, x, y, width, height, options.radius);
224-
if (options.type === 'bevel') return this.addBevelImage(buffer, x, y, width, height, options.radius);
224+
if (isNaN(options.radius)) options.radius = 10;
225+
if (options.type === 'round') this.createRoundClip(x + options.radius, y + options.radius, options.radius);
226+
if (options.type === 'bevel') this.createBeveledClip(x, y, width, height, options.radius);
225227
}
226-
this.save();
227228
const image = new Canvas.Image();
228229
image.onload = () => this.context.drawImage(image, x, y, width, height);
229230
image.src = buffer;
@@ -242,8 +243,7 @@ class CanvasConstructor {
242243
* @chainable
243244
*/
244245
addRoundImage(buffer, x, y, width, height, radius) {
245-
this.createRoundClip(x + radius, y + radius, radius);
246-
return this.addImage(buffer, x, y, width, height, {});
246+
return this.addImage(buffer, x, y, width, height, { type: 'round', radius });
247247
}
248248

249249
/**
@@ -258,8 +258,7 @@ class CanvasConstructor {
258258
* @chainable
259259
*/
260260
addBevelImage(buffer, x, y, width, height, radius) {
261-
this.createBeveledClip(x, y, width, height, radius);
262-
return this.addImage(buffer, x, y, width, height, {});
261+
return this.addImage(buffer, x, y, width, height, { type: 'bevel', radius });
263262
}
264263

265264
/**

0 commit comments

Comments
 (0)