Skip to content

Commit

Permalink
feat(images): allow copy image
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelass committed Aug 1, 2023
1 parent a43bac1 commit 27eb284
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ The context menu offers additional options for nodes, groups, colors, and the ca
- Custom color option (only available in "default" Color Mode).
- Show title on Reroute node
- Render Reroute as dot
- Copy Images


<div align="center">
Expand All @@ -165,6 +166,11 @@ The context menu offers additional options for nodes, groups, colors, and the ca
<p>Reroute as dot</p>
</div>

<div align="center">
<img src="https://github.com/failfa-st/failfast-comfyui-extensions/assets/1148334/f41b4aff-9677-4faf-85cb-86ce497d6240" alt="Copy images" >
<p>Copy Image</p>
</div>


**Groups**

Expand Down
51 changes: 51 additions & 0 deletions extensions/images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Coded with love by Failfa.st
* LICENSE: AGPL 3.0
* https://github.com/failfa-st/failfast-comfyui-extensions/blob/main/LICENSE
*
* Visit https://github.com/failfa-st/failfast-comfyui-extensions for more info
*
* Homepage: https://failfa.st
* GitHub: https://github.com/failfa-st
* Discord: https://discord.com/invite/m3TBB9XEkb
*/
import { app } from "/scripts/app.js";

const imagesName = "Failfast.images";

function copyImageToClipboard(img) {
const canvas = document.createElement("canvas");
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
const context = canvas.getContext("2d");
context.drawImage(img, 0, 0);
canvas.toBlob(function (blob) {
const items = [new ClipboardItem({ "image/png": blob })];
navigator.clipboard.write(items);
});
canvas.remove();
}
app.registerExtension({
name: imagesName,
async init(app) {
const getNodeMenuOptions = LGraphCanvas.prototype.getNodeMenuOptions;
LGraphCanvas.prototype.getNodeMenuOptions = function (node) {
const options = getNodeMenuOptions.apply(this, arguments);
const isImageMenu = options.some(
(option) => option?.content === "Save Image",
);
if (isImageMenu) {
options.splice(2, 0, {
content: "Copy Image",
callback() {
const [img] = node.imgs;
if (img) {
copyImageToClipboard(img);
}
},
});
}
return options;
};
},
});

0 comments on commit 27eb284

Please sign in to comment.