Skip to content

Commit

Permalink
feat: add copy image in share menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn authored and psychedelicious committed Feb 4, 2023
1 parent 702a929 commit 81e174b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions invokeai/frontend/public/locales/parameters/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"sendTo": "Send to",
"sendToImg2Img": "Send to Image to Image",
"sendToUnifiedCanvas": "Send To Unified Canvas",
"copyImage": "Copy Image",
"copyImageToLink": "Copy Image To Link",
"downloadImage": "Download Image",
"openInViewer": "Open In Viewer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ const CurrentImageButtons = () => {
dispatch(setActiveTab('img2img'));
};

const handleCopyImage = async () => {
if (!currentImage) return;

const blob = await fetch(currentImage.url).then((res) => res.blob());
const data = [new ClipboardItem({ [blob.type]: blob })];

await navigator.clipboard.write(data);

toast({
title: t('toast:imageCopied'),
status: 'success',
duration: 2500,
isClosable: true,
});
};

const handleCopyImageLink = () => {
navigator.clipboard
.writeText(
Expand Down Expand Up @@ -401,6 +417,14 @@ const CurrentImageButtons = () => {
>
{t('parameters:sendToUnifiedCanvas')}
</IAIButton>

<IAIButton
size={'sm'}
onClick={handleCopyImage}
leftIcon={<FaCopy />}
>
{t('parameters:copyImage')}
</IAIButton>
<IAIButton
size={'sm'}
onClick={handleCopyImageLink}
Expand Down

0 comments on commit 81e174b

Please sign in to comment.