mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add util to get blobs from layers
This commit is contained in:
parent
52ba4966c9
commit
c89a24d1ea
@ -1,4 +1,5 @@
|
||||
import { Flex } from '@invoke-ai/ui-library';
|
||||
/* eslint-disable i18next/no-literal-string */
|
||||
import { Button, Flex } from '@invoke-ai/ui-library';
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { useAppSelector } from 'app/store/storeHooks';
|
||||
import { AddLayerButton } from 'features/regionalPrompts/components/AddLayerButton';
|
||||
@ -7,6 +8,7 @@ import { LayerListItem } from 'features/regionalPrompts/components/LayerListItem
|
||||
import { RegionalPromptsStage } from 'features/regionalPrompts/components/RegionalPromptsStage';
|
||||
import { ToolChooser } from 'features/regionalPrompts/components/ToolChooser';
|
||||
import { selectRegionalPromptsSlice } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { getLayerBlobs } from 'features/regionalPrompts/util/getLayerBlobs';
|
||||
|
||||
const selectLayerIdsReversed = createSelector(selectRegionalPromptsSlice, (regionalPrompts) =>
|
||||
regionalPrompts.layers.map((l) => l.id).reverse()
|
||||
@ -17,6 +19,7 @@ export const RegionalPromptsEditor = () => {
|
||||
return (
|
||||
<Flex gap={4}>
|
||||
<Flex flexDir="column" w={200} gap={4}>
|
||||
<Button onClick={getLayerBlobs}>DEBUG LAYERS</Button>
|
||||
<AddLayerButton />
|
||||
<BrushSize />
|
||||
<ToolChooser />
|
||||
|
@ -56,7 +56,7 @@ export const RegionalPromptsStage: React.FC = memo(() => {
|
||||
sx={stageSx}
|
||||
>
|
||||
{layers.map((layer) => (
|
||||
<Layer key={layer.id}>
|
||||
<Layer key={layer.id} id={layer.id} name="regionalPromptLayer">
|
||||
{layer.objects.map((obj) => {
|
||||
if (obj.kind === 'line') {
|
||||
return <LineComponent key={obj.id} line={obj} color={layer.color} />;
|
||||
|
@ -0,0 +1,26 @@
|
||||
import { getStore } from 'app/store/nanostores/store';
|
||||
import openBase64ImageInTab from 'common/util/openBase64ImageInTab';
|
||||
import { blobToDataURL } from 'features/canvas/util/blobToDataURL';
|
||||
import { $stage } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { assert } from 'tsafe';
|
||||
|
||||
export const getLayerBlobs = async () => {
|
||||
const state = getStore().getState();
|
||||
const stage = $stage.get();
|
||||
assert(stage !== null, 'Stage is null');
|
||||
const stageLayers = stage.getLayers().filter((l) => l.name() === 'regionalPromptLayer');
|
||||
for (const layer of stageLayers) {
|
||||
const blob = await new Promise<Blob>((resolve) => {
|
||||
layer.toBlob({
|
||||
callback: (blob) => {
|
||||
assert(blob, 'Blob is null');
|
||||
resolve(blob);
|
||||
},
|
||||
});
|
||||
});
|
||||
const base64 = await blobToDataURL(blob);
|
||||
const prompt = state.regionalPrompts.layers.find((l) => l.id === layer.id())?.prompt;
|
||||
assert(prompt !== undefined, 'Prompt is undefined');
|
||||
openBase64ImageInTab([{ base64, caption: prompt }]);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user