@gradio/imageeditor 0.11.7 → 0.11.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/shared/InteractiveImageEditor.svelte +1 -0
- package/dist/shared/tools/Brush.svelte +4 -1
- package/dist/shared/tools/Sources.svelte +3 -1
- package/dist/shared/tools/Sources.svelte.d.ts +1 -0
- package/dist/shared/tools/sources.d.ts +1 -1
- package/dist/shared/tools/sources.js +22 -2
- package/package.json +7 -7
- package/shared/InteractiveImageEditor.svelte +1 -0
- package/shared/tools/Brush.svelte +5 -6
- package/shared/tools/Sources.svelte +3 -1
- package/shared/tools/sources.ts +39 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @gradio/imageeditor
|
|
2
2
|
|
|
3
|
+
## 0.11.9
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- [#10037](https://github.com/gradio-app/gradio/pull/10037) [`d0b74ba`](https://github.com/gradio-app/gradio/commit/d0b74ba281b37d8883a4e4fbb98c5922600ca41e) - Ensure toolbar stays visible for large images in ImageEditor. Thanks @hannahblair!
|
|
8
|
+
- [#10041](https://github.com/gradio-app/gradio/pull/10041) [`c1fa13c`](https://github.com/gradio-app/gradio/commit/c1fa13c9c057ce05a325782e58b409cde79383b8) - Ensure ImageEditor brush colour is updated when changed. Thanks @hannahblair!
|
|
9
|
+
|
|
10
|
+
### Dependency updates
|
|
11
|
+
|
|
12
|
+
- @gradio/atoms@0.11.2
|
|
13
|
+
- @gradio/utils@0.9.0
|
|
14
|
+
- @gradio/statustracker@0.9.6
|
|
15
|
+
- @gradio/upload@0.14.2
|
|
16
|
+
- @gradio/image@0.17.0
|
|
17
|
+
|
|
18
|
+
## 0.11.8
|
|
19
|
+
|
|
20
|
+
### Dependency updates
|
|
21
|
+
|
|
22
|
+
- @gradio/atoms@0.11.1
|
|
23
|
+
- @gradio/client@1.8.0
|
|
24
|
+
- @gradio/utils@0.8.0
|
|
25
|
+
- @gradio/upload@0.14.1
|
|
26
|
+
- @gradio/statustracker@0.9.5
|
|
27
|
+
- @gradio/image@0.16.8
|
|
28
|
+
|
|
3
29
|
## 0.11.7
|
|
4
30
|
|
|
5
31
|
### Dependency updates
|
|
@@ -15,8 +15,11 @@ export let color_mode = void 0;
|
|
|
15
15
|
export let mode;
|
|
16
16
|
$:
|
|
17
17
|
processed_colors = colors ? colors.map(process_color).filter((_, i) => i < 4) : [];
|
|
18
|
+
let selected_color = process_color(default_color || "#000000");
|
|
18
19
|
$:
|
|
19
|
-
|
|
20
|
+
if (mode === "draw") {
|
|
21
|
+
current_color.set(selected_color);
|
|
22
|
+
}
|
|
20
23
|
let brush_options = false;
|
|
21
24
|
const {
|
|
22
25
|
pixi,
|
|
@@ -24,6 +24,7 @@ export let i18n;
|
|
|
24
24
|
export let upload;
|
|
25
25
|
export let stream_handler;
|
|
26
26
|
export let dragging;
|
|
27
|
+
export let max_height;
|
|
27
28
|
const { active_tool } = getContext(TOOL_KEY);
|
|
28
29
|
const { pixi, dimensions, register_context, reset, editor_box } = getContext(EDITOR_KEY);
|
|
29
30
|
export let active_mode = null;
|
|
@@ -88,7 +89,8 @@ async function set_background() {
|
|
|
88
89
|
$pixi.background_container,
|
|
89
90
|
$pixi.renderer,
|
|
90
91
|
background,
|
|
91
|
-
$pixi.resize
|
|
92
|
+
$pixi.resize,
|
|
93
|
+
max_height
|
|
92
94
|
);
|
|
93
95
|
$dimensions = await add_image.start();
|
|
94
96
|
if (should_reset) {
|
|
@@ -15,7 +15,7 @@ interface BgImageCommand extends Command {
|
|
|
15
15
|
* @param resize The function to resize the canvas.
|
|
16
16
|
* @returns A command that can be used to undo the action.
|
|
17
17
|
*/
|
|
18
|
-
export declare function add_bg_image(container: Container, renderer: IRenderer, background: Blob | File, resize: (width: number, height: number) => void): BgImageCommand;
|
|
18
|
+
export declare function add_bg_image(container: Container, renderer: IRenderer, background: Blob | File, resize: (width: number, height: number) => void, max_height?: number): BgImageCommand;
|
|
19
19
|
/**
|
|
20
20
|
* Command that sets a background
|
|
21
21
|
*/
|
|
@@ -9,15 +9,35 @@ import { make_graphics } from "../utils/pixi";
|
|
|
9
9
|
* @param resize The function to resize the canvas.
|
|
10
10
|
* @returns A command that can be used to undo the action.
|
|
11
11
|
*/
|
|
12
|
-
export function add_bg_image(container, renderer, background, resize) {
|
|
12
|
+
export function add_bg_image(container, renderer, background, resize, max_height = 450) {
|
|
13
13
|
let sprite;
|
|
14
|
+
function calculate_dimensions(width, height, max_height) {
|
|
15
|
+
const MAX_HEIGHT = max_height * 1.5;
|
|
16
|
+
const MAX_WIDTH = MAX_HEIGHT * 2;
|
|
17
|
+
let new_width = width;
|
|
18
|
+
let new_height = height;
|
|
19
|
+
if (height > MAX_HEIGHT) {
|
|
20
|
+
const ratio = MAX_HEIGHT / height;
|
|
21
|
+
new_width = width * ratio;
|
|
22
|
+
new_height = MAX_HEIGHT;
|
|
23
|
+
}
|
|
24
|
+
if (new_width > MAX_WIDTH) {
|
|
25
|
+
const ratio = MAX_WIDTH / new_width;
|
|
26
|
+
new_width = MAX_WIDTH;
|
|
27
|
+
new_height = new_height * ratio;
|
|
28
|
+
}
|
|
29
|
+
return [Math.round(new_width), Math.round(new_height)];
|
|
30
|
+
}
|
|
14
31
|
return {
|
|
15
32
|
async start() {
|
|
16
33
|
container.removeChildren();
|
|
17
34
|
const img = await createImageBitmap(background);
|
|
18
35
|
const bitmap_texture = Texture.from(img);
|
|
19
36
|
sprite = new Sprite(bitmap_texture);
|
|
20
|
-
|
|
37
|
+
const [new_width, new_height] = calculate_dimensions(sprite.width, sprite.height, max_height);
|
|
38
|
+
sprite.width = new_width;
|
|
39
|
+
sprite.height = new_height;
|
|
40
|
+
return [new_width, new_height];
|
|
21
41
|
},
|
|
22
42
|
async execute() {
|
|
23
43
|
// renderer.resize(sprite.width, sprite.height);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/imageeditor",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.9",
|
|
4
4
|
"description": "Gradio UI packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
"@types/tinycolor2": "^1.4.6",
|
|
11
11
|
"pixi.js": "^7.3.2",
|
|
12
12
|
"tinycolor2": "^1.6.0",
|
|
13
|
+
"@gradio/atoms": "^0.11.2",
|
|
14
|
+
"@gradio/client": "^1.8.0",
|
|
13
15
|
"@gradio/icons": "^0.8.1",
|
|
14
|
-
"@gradio/
|
|
15
|
-
"@gradio/
|
|
16
|
-
"@gradio/statustracker": "^0.9.
|
|
17
|
-
"@gradio/
|
|
18
|
-
"@gradio/client": "^1.7.1",
|
|
19
|
-
"@gradio/utils": "^0.7.0",
|
|
16
|
+
"@gradio/image": "^0.17.0",
|
|
17
|
+
"@gradio/upload": "^0.14.2",
|
|
18
|
+
"@gradio/statustracker": "^0.9.6",
|
|
19
|
+
"@gradio/utils": "^0.9.0",
|
|
20
20
|
"@gradio/wasm": "^0.15.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
@@ -47,12 +47,11 @@
|
|
|
47
47
|
? colors.map(process_color).filter((_, i) => i < 4)
|
|
48
48
|
: [];
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
: process_color(default_color);
|
|
50
|
+
let selected_color = process_color(default_color || "#000000");
|
|
51
|
+
|
|
52
|
+
$: if (mode === "draw") {
|
|
53
|
+
current_color.set(selected_color);
|
|
54
|
+
}
|
|
56
55
|
|
|
57
56
|
let brush_options: brush_option_type = false;
|
|
58
57
|
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
export let upload: Client["upload"];
|
|
29
29
|
export let stream_handler: Client["stream"];
|
|
30
30
|
export let dragging: boolean;
|
|
31
|
+
export let max_height: number;
|
|
31
32
|
|
|
32
33
|
const { active_tool } = getContext<ToolContext>(TOOL_KEY);
|
|
33
34
|
const { pixi, dimensions, register_context, reset, editor_box } =
|
|
@@ -108,7 +109,8 @@
|
|
|
108
109
|
$pixi.background_container,
|
|
109
110
|
$pixi.renderer,
|
|
110
111
|
background,
|
|
111
|
-
$pixi.resize
|
|
112
|
+
$pixi.resize,
|
|
113
|
+
max_height
|
|
112
114
|
);
|
|
113
115
|
$dimensions = await add_image.start();
|
|
114
116
|
|
package/shared/tools/sources.ts
CHANGED
|
@@ -33,16 +33,53 @@ export function add_bg_image(
|
|
|
33
33
|
container: Container,
|
|
34
34
|
renderer: IRenderer,
|
|
35
35
|
background: Blob | File,
|
|
36
|
-
resize: (width: number, height: number) => void
|
|
36
|
+
resize: (width: number, height: number) => void,
|
|
37
|
+
max_height = 450
|
|
37
38
|
): BgImageCommand {
|
|
38
39
|
let sprite: Sprite & DisplayObject;
|
|
40
|
+
|
|
41
|
+
function calculate_dimensions(
|
|
42
|
+
width: number,
|
|
43
|
+
height: number,
|
|
44
|
+
max_height: number
|
|
45
|
+
): [number, number] {
|
|
46
|
+
const MAX_HEIGHT = max_height * 1.5;
|
|
47
|
+
const MAX_WIDTH = MAX_HEIGHT * 2;
|
|
48
|
+
|
|
49
|
+
let new_width = width;
|
|
50
|
+
let new_height = height;
|
|
51
|
+
|
|
52
|
+
if (height > MAX_HEIGHT) {
|
|
53
|
+
const ratio = MAX_HEIGHT / height;
|
|
54
|
+
new_width = width * ratio;
|
|
55
|
+
new_height = MAX_HEIGHT;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (new_width > MAX_WIDTH) {
|
|
59
|
+
const ratio = MAX_WIDTH / new_width;
|
|
60
|
+
new_width = MAX_WIDTH;
|
|
61
|
+
new_height = new_height * ratio;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return [Math.round(new_width), Math.round(new_height)];
|
|
65
|
+
}
|
|
66
|
+
|
|
39
67
|
return {
|
|
40
68
|
async start() {
|
|
41
69
|
container.removeChildren();
|
|
42
70
|
const img = await createImageBitmap(background);
|
|
43
71
|
const bitmap_texture = Texture.from(img);
|
|
44
72
|
sprite = new Sprite(bitmap_texture) as Sprite & DisplayObject;
|
|
45
|
-
|
|
73
|
+
|
|
74
|
+
const [new_width, new_height] = calculate_dimensions(
|
|
75
|
+
sprite.width,
|
|
76
|
+
sprite.height,
|
|
77
|
+
max_height
|
|
78
|
+
);
|
|
79
|
+
sprite.width = new_width;
|
|
80
|
+
sprite.height = new_height;
|
|
81
|
+
|
|
82
|
+
return [new_width, new_height];
|
|
46
83
|
},
|
|
47
84
|
async execute() {
|
|
48
85
|
// renderer.resize(sprite.width, sprite.height);
|