Skip to content

Commit 83d3f6c

Browse files
committed
testing
1 parent 847610c commit 83d3f6c

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

demo/blocks_flipper/image.png

842 Bytes
Loading

demo/blocks_flipper/run.py

+45-23
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,51 @@
1-
import numpy as np
1+
# import numpy as np
2+
# import gradio as gr
3+
4+
# def flip_text(x):
5+
# return x[::-1]
6+
7+
# def flip_image(x):
8+
# return np.fliplr(x)
9+
10+
# with gr.Blocks() as demo:
11+
# gr.Markdown("Flip text or image files using this demo.")
12+
# with gr.Tab("Flip Text"):
13+
# text_input = gr.Textbox()
14+
# text_output = gr.Textbox()
15+
# text_button = gr.Button("Flip")
16+
# with gr.Tab("Flip Image"):
17+
# with gr.Row():
18+
# image_input = gr.Image()
19+
# image_output = gr.Image()
20+
# image_button = gr.Button("Flip")
21+
22+
# with gr.Accordion("Open for More!"):
23+
# gr.Markdown("Look at me...")
24+
25+
# text_button.click(flip_text, inputs=text_input, outputs=text_output)
26+
# image_button.click(flip_image, inputs=image_input, outputs=image_output)
27+
28+
# if __name__ == "__main__":
29+
# demo.launch()
30+
231
import gradio as gr
32+
from PIL import Image
33+
34+
img = Image.new("RGB", (512, 512), (0, 0, 0))
35+
img.save("image.png", "PNG")
36+
37+
print(img)
338

4-
def flip_text(x):
5-
return x[::-1]
639

7-
def flip_image(x):
8-
return np.fliplr(x)
40+
def save_image(image):
41+
image.save("colorede.png")
42+
return image
43+
944

1045
with gr.Blocks() as demo:
11-
gr.Markdown("Flip text or image files using this demo.")
12-
with gr.Tab("Flip Text"):
13-
text_input = gr.Textbox()
14-
text_output = gr.Textbox()
15-
text_button = gr.Button("Flip")
16-
with gr.Tab("Flip Image"):
17-
with gr.Row():
18-
image_input = gr.Image()
19-
image_output = gr.Image()
20-
image_button = gr.Button("Flip")
21-
22-
with gr.Accordion("Open for More!"):
23-
gr.Markdown("Look at me...")
24-
25-
text_button.click(flip_text, inputs=text_input, outputs=text_output)
26-
image_button.click(flip_image, inputs=image_input, outputs=image_output)
27-
46+
image = gr.Image(value="image.png", interactive=True, tool="color-sketch")
47+
button = gr.Button()
48+
button.click(save_image, inputs=image, outputs=[])
49+
2850
if __name__ == "__main__":
29-
demo.launch()
51+
demo.launch()

ui/packages/image/src/Sketch.svelte

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
export let brush_color = "#0b0f19";
1515
export let brush_radius = 50;
1616
export let source;
17+
$: console.log($$props.width, old_height);
1718
1819
export let width = 400;
1920
export let height = 200;
@@ -32,6 +33,7 @@
3233
3334
$: {
3435
if (mounted && value_img !== last_value_img) {
36+
console.log("boo");
3537
last_value_img = value_img;
3638
3739
clear();
@@ -150,6 +152,7 @@
150152
151153
canvas_observer = new ResizeObserver((entries, observer, ...rest) => {
152154
handle_canvas_resize(entries, observer);
155+
console.log("RESIZE OBSERVER");
153156
});
154157
canvas_observer.observe(canvas_container);
155158
@@ -281,6 +284,7 @@
281284
let old_container_height = 0;
282285
283286
let handle_canvas_resize = async () => {
287+
console.log("RESIZE");
284288
if (
285289
width === old_width &&
286290
height === old_height &&
@@ -289,6 +293,7 @@
289293
return;
290294
}
291295
const dimensions = { width: width, height: height };
296+
console.log({ dimensions });
292297
293298
const container_dimensions = {
294299
height: container_height,
@@ -311,7 +316,8 @@
311316
old_height = height;
312317
old_width = width;
313318
old_container_height = container_height;
314-
}, 100);
319+
}, 10);
320+
await tick();
315321
316322
clear();
317323
};
@@ -325,6 +331,7 @@
325331
326332
$: {
327333
if (width || height) {
334+
console.log("WIDTH?HEIGHT RESIZE");
328335
handle_canvas_resize();
329336
}
330337
}
@@ -334,6 +341,7 @@
334341
await tick();
335342
336343
const dpr = window.devicePixelRatio || 1;
344+
console.log(dpr, dimensions);
337345
canvas.width = dimensions.width * (scale ? dpr : 1);
338346
canvas.height = dimensions.height * (scale ? dpr : 1);
339347

0 commit comments

Comments
 (0)