Skip to content

Commit

Permalink
Create Faster Blur Uri.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistium authored Sep 28, 2024
1 parent eea92bc commit 58c6a63
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions files/Faster Blur Uri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class BlurImageExtension {
getInfo() {
return {
id: 'blurImage',
name: 'Blur Image',
blocks: [
{
opcode: 'blurImage',
blockType: Scratch.BlockType.REPORTER,
text: 'blur image [URL] by [BLUR] pixels',
arguments: {
URL: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'https://example.com/image.png'
},
BLUR: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 5
}
}
}
]
};
}

blurImage(args) {
const dataUri = args.URL;
const blur = args.BLUR;
return new Promise((resolve) => {
var image = new Image();
image.crossOrigin = "anonymous";
image.onload = function() {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = image.width;
canvas.height = image.height;
ctx.filter = "blur(" + blur + "px)";
ctx.drawImage(image, 0, 0, image.width, image.height);
resolve(canvas.toDataURL());
};
image.src = dataUri;
});
}
}

Scratch.extensions.register(new BlurImageExtension());

0 comments on commit 58c6a63

Please sign in to comment.