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

add shadow effect

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -40,7 +40,8 @@ def add_text_to_image(
40
  opacity,
41
  x_position,
42
  y_position,
43
- thickness
 
44
  ):
45
  """
46
  Add text to an image with customizable properties
@@ -92,15 +93,20 @@ def add_text_to_image(
92
  # Create final color with opacity
93
  text_color = (*rgb_color, int(opacity))
94
 
95
- # Draw the text with stroke for thickness
96
- add_text_with_stroke(
 
 
 
97
  draw,
98
  text,
99
  actual_x,
100
  actual_y,
101
  font,
102
  text_color,
103
- int(thickness)
 
 
104
  )
105
 
106
  # Combine the original image with the text overlay
@@ -143,6 +149,7 @@ def create_interface():
143
  label="X Position (%)")
144
  y_position = gr.Slider(minimum=0, maximum=100, value=50, step=1,
145
  label="Y Position (%)")
 
146
 
147
  with gr.Column():
148
  # Output image
@@ -162,7 +169,8 @@ def create_interface():
162
  opacity_slider,
163
  x_position,
164
  y_position,
165
- thickness
 
166
  ],
167
  outputs=output_image
168
  )
@@ -178,7 +186,8 @@ def create_interface():
178
  150,
179
  50,
180
  21,
181
- 9
 
182
  ],
183
  [
184
  "pear.jpg",
@@ -188,7 +197,8 @@ def create_interface():
188
  100,
189
  50,
190
  2,
191
- 5
 
192
  ],
193
  [
194
  "sample_text_image.jpeg",
@@ -198,7 +208,8 @@ def create_interface():
198
  150,
199
  50,
200
  2,
201
- 8
 
202
  ],
203
  ],
204
  inputs=[
@@ -209,7 +220,8 @@ def create_interface():
209
  opacity_slider,
210
  x_position,
211
  y_position,
212
- thickness
 
213
  ],
214
  outputs=output_image,
215
  fn=add_text_to_image,
 
40
  opacity,
41
  x_position,
42
  y_position,
43
+ thickness,
44
+ use_shadow
45
  ):
46
  """
47
  Add text to an image with customizable properties
 
93
  # Create final color with opacity
94
  text_color = (*rgb_color, int(opacity))
95
 
96
+ # Calculate shadow offset based on font size
97
+ shadow_offset = (int(font_size * 0.05), int(font_size * 0.05))
98
+
99
+ # Draw the text with effects
100
+ add_text_with_effects(
101
  draw,
102
  text,
103
  actual_x,
104
  actual_y,
105
  font,
106
  text_color,
107
+ int(thickness),
108
+ shadow=use_shadow,
109
+ shadow_offset=shadow_offset
110
  )
111
 
112
  # Combine the original image with the text overlay
 
149
  label="X Position (%)")
150
  y_position = gr.Slider(minimum=0, maximum=100, value=50, step=1,
151
  label="Y Position (%)")
152
+ shadow_checkbox = gr.Checkbox(label="Add Shadow Effect", value=False)
153
 
154
  with gr.Column():
155
  # Output image
 
169
  opacity_slider,
170
  x_position,
171
  y_position,
172
+ thickness,
173
+ shadow_checkbox
174
  ],
175
  outputs=output_image
176
  )
 
186
  150,
187
  50,
188
  21,
189
+ 9,
190
+ True
191
  ],
192
  [
193
  "pear.jpg",
 
197
  100,
198
  50,
199
  2,
200
+ 5,
201
+ True
202
  ],
203
  [
204
  "sample_text_image.jpeg",
 
208
  150,
209
  50,
210
  2,
211
+ 8,
212
+ True
213
  ],
214
  ],
215
  inputs=[
 
220
  opacity_slider,
221
  x_position,
222
  y_position,
223
+ thickness,
224
+ shadow_checkbox
225
  ],
226
  outputs=output_image,
227
  fn=add_text_to_image,