ysharma HF staff commited on
Commit
cd3441f
·
verified ·
1 Parent(s): e795b64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -8,12 +8,25 @@ import uuid
8
 
9
  client = Client("ysharma/BiRefNet_for_text_writing")
10
 
11
- def add_text_with_stroke(draw, text, x, y, font, text_color, stroke_width):
12
- """Helper function to draw text with stroke"""
13
- # Draw the stroke/outline
14
- for adj_x in range(-stroke_width, stroke_width + 1):
15
- for adj_y in range(-stroke_width, stroke_width + 1):
16
- draw.text((x + adj_x, y + adj_y), text, font=font, fill=text_color)
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  def remove_background(image):
19
  # Save the image to a specific location
@@ -221,7 +234,7 @@ def create_interface():
221
  x_position,
222
  y_position,
223
  thickness,
224
- shadow_checkbox
225
  ],
226
  outputs=output_image,
227
  fn=add_text_to_image,
 
8
 
9
  client = Client("ysharma/BiRefNet_for_text_writing")
10
 
11
+ def add_text_with_effects(draw, text, x, y, font, text_color, stroke_width, shadow=False, shadow_offset=(5, 5)):
12
+ """Helper function to draw text with stroke and optional shadow"""
13
+ # Draw shadow first if enabled
14
+ if shadow:
15
+ # Create shadow color (darker version of text color or black)
16
+ shadow_color = (0, 0, 0, text_color[3]) # Black with same opacity as text
17
+
18
+ # Draw the shadow text with stroke effect
19
+ shadow_x = x + shadow_offset[0]
20
+ shadow_y = y + shadow_offset[1]
21
+
22
+ for adj_x in range(-stroke_width, stroke_width + 1):
23
+ for adj_y in range(-stroke_width, stroke_width + 1):
24
+ draw.text(
25
+ (shadow_x + adj_x, shadow_y + adj_y),
26
+ text,
27
+ font=font,
28
+ fill=shadow_color
29
+ )
30
 
31
  def remove_background(image):
32
  # Save the image to a specific location
 
234
  x_position,
235
  y_position,
236
  thickness,
237
+ shadow_checkbox,
238
  ],
239
  outputs=output_image,
240
  fn=add_text_to_image,