From 5478d2a15e5e98bc6745fa72677271f207b6ad76 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Fri, 3 Feb 2023 12:10:33 +0800 Subject: [PATCH] feat: add copy image in share menu --- .../public/locales/parameters/en.json | 1 + .../components/CurrentImageButtons.tsx | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/invokeai/frontend/public/locales/parameters/en.json b/invokeai/frontend/public/locales/parameters/en.json index 17a439cf11..5bca8b0950 100644 --- a/invokeai/frontend/public/locales/parameters/en.json +++ b/invokeai/frontend/public/locales/parameters/en.json @@ -48,6 +48,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", diff --git a/invokeai/frontend/src/features/gallery/components/CurrentImageButtons.tsx b/invokeai/frontend/src/features/gallery/components/CurrentImageButtons.tsx index cd338abaea..13275c4cbf 100644 --- a/invokeai/frontend/src/features/gallery/components/CurrentImageButtons.tsx +++ b/invokeai/frontend/src/features/gallery/components/CurrentImageButtons.tsx @@ -133,6 +133,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( @@ -412,6 +428,14 @@ const CurrentImageButtons = () => { > {t('parameters:sendToUnifiedCanvas')} + + } + > + {t('parameters:copyImage')} +