gaur3009 commited on
Commit
012c6d8
1 Parent(s): f737883

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -9,12 +9,13 @@ def apply_color(image, color):
9
 
10
  def add_design(image, design, position):
11
  if design:
 
12
  image.paste(design, position, design)
13
  return image
14
 
15
  def resize_image(image, size):
16
  if size:
17
- return image.resize(size)
18
  return image
19
 
20
  def rotate_image(image, angle):
@@ -34,7 +35,8 @@ def add_text(image, text, position, font_size, font_color):
34
  draw.text(position, text, fill=font_color, font=font)
35
  return image
36
 
37
- def process_image(image, color, design, design_position, text, text_position, font_size, font_color, resize, rotate, crop_coords):
 
38
  if color:
39
  image = apply_color(image, color)
40
  if design:
@@ -48,6 +50,7 @@ def process_image(image, color, design, design_position, text, text_position, fo
48
  if crop_coords:
49
  image = crop_image(image, crop_coords)
50
  return image
 
51
  def get_crop_coords(crop_sketch):
52
  if crop_sketch:
53
  x_coords = [point[0] for point in crop_sketch]
@@ -60,7 +63,7 @@ text_position = (50, 50) # Default position for text
60
 
61
  interface = gr.Interface(
62
  fn=lambda image, color, design, design_position, text, text_position, font_size, font_color, resize, rotate, crop_sketch: process_image(
63
- image, color, design, design_position, text, text_position, font_size, font_color, resize, rotate, get_crop_coords(crop_sketch)
64
  ),
65
  inputs=[
66
  gr.Image(type="pil"),
@@ -69,14 +72,14 @@ interface = gr.Interface(
69
  gr.Sketchpad(label="Design Position"),
70
  gr.Textbox(label="Text"),
71
  gr.Sketchpad(label="Text Position"),
72
- gr.Slider(10, 100, step=1, default=20, label="Font Size"),
73
  gr.ColorPicker(label="Font Color"),
74
- gr.Slider(50, 1000, step=1, default=None, label="Resize"),
75
- gr.Slider(0, 360, step=1, default=None, label="Rotate"),
76
  gr.Sketchpad(label="Crop Area")
77
  ],
78
  outputs=gr.Image(type="pil"),
79
  live=True
80
  )
81
 
82
- interface.launch()
 
9
 
10
  def add_design(image, design, position):
11
  if design:
12
+ design = Image.open(design).convert("RGBA")
13
  image.paste(design, position, design)
14
  return image
15
 
16
  def resize_image(image, size):
17
  if size:
18
+ return image.resize((size, size))
19
  return image
20
 
21
  def rotate_image(image, angle):
 
35
  draw.text(position, text, fill=font_color, font=font)
36
  return image
37
 
38
+ def process_image(image, color, design, design_position, text, text_position, font_size, font_color, resize, rotate, crop_sketch):
39
+ crop_coords = get_crop_coords(crop_sketch)
40
  if color:
41
  image = apply_color(image, color)
42
  if design:
 
50
  if crop_coords:
51
  image = crop_image(image, crop_coords)
52
  return image
53
+
54
  def get_crop_coords(crop_sketch):
55
  if crop_sketch:
56
  x_coords = [point[0] for point in crop_sketch]
 
63
 
64
  interface = gr.Interface(
65
  fn=lambda image, color, design, design_position, text, text_position, font_size, font_color, resize, rotate, crop_sketch: process_image(
66
+ image, color, design, design_position, text, text_position, font_size, font_color, resize, rotate, crop_sketch
67
  ),
68
  inputs=[
69
  gr.Image(type="pil"),
 
72
  gr.Sketchpad(label="Design Position"),
73
  gr.Textbox(label="Text"),
74
  gr.Sketchpad(label="Text Position"),
75
+ gr.Slider(10, 100, step=1, value=20, label="Font Size"),
76
  gr.ColorPicker(label="Font Color"),
77
+ gr.Slider(50, 1000, step=1, value=100, label="Resize"),
78
+ gr.Slider(0, 360, step=1, value=0, label="Rotate"),
79
  gr.Sketchpad(label="Crop Area")
80
  ],
81
  outputs=gr.Image(type="pil"),
82
  live=True
83
  )
84
 
85
+ interface.launch()