mirror of
https://github.com/sun-guannan/CapCutAPI.git
synced 2025-11-25 03:15:00 +08:00
add text shadow feature
This commit is contained in:
@@ -349,6 +349,19 @@ def add_text():
|
||||
background_color = data.get('background_color', "#000000")
|
||||
background_style = data.get('background_style', 0)
|
||||
background_alpha = data.get('background_alpha', 0.0)
|
||||
background_round_radius = data.get('background_round_radius', 0.0)
|
||||
background_height = data.get('background_height', 0.14) # 背景高度,范围0.0-1.0
|
||||
background_width = data.get('background_width', 0.14) # 背景宽度,范围0.0-1.0
|
||||
background_horizontal_offset = data.get('background_horizontal_offset', 0.5) # 背景水平偏移,范围0.0-1.0
|
||||
background_vertical_offset = data.get('background_vertical_offset', 0.5) # 背景垂直偏移,范围0.0-1.0
|
||||
|
||||
# 阴影参数
|
||||
shadow_enabled = data.get('shadow_enabled', False) # 是否启用阴影
|
||||
shadow_alpha = data.get('shadow_alpha', 0.9) # 阴影透明度,范围0.0-1.0
|
||||
shadow_angle = data.get('shadow_angle', -45.0) # 阴影角度,范围-180.0-180.0
|
||||
shadow_color = data.get('shadow_color', "#000000") # 阴影颜色
|
||||
shadow_distance = data.get('shadow_distance', 5.0) # 阴影距离
|
||||
shadow_smoothing = data.get('shadow_smoothing', 0.15) # 阴影平滑度,范围0.0-1.0
|
||||
|
||||
# Bubble and decorative text effects
|
||||
bubble_effect_id = data.get('bubble_effect_id')
|
||||
@@ -363,6 +376,50 @@ def add_text():
|
||||
outro_animation = data.get('outro_animation')
|
||||
outro_duration = data.get('outro_duration', 0.5)
|
||||
|
||||
# 新增多样式文本参数
|
||||
text_styles_data = data.get('text_styles', [])
|
||||
text_styles = None
|
||||
if text_styles_data:
|
||||
text_styles = []
|
||||
for style_data in text_styles_data:
|
||||
# 获取样式范围
|
||||
start_pos = style_data.get('start', 0)
|
||||
end_pos = style_data.get('end', 0)
|
||||
|
||||
# 创建文本样式
|
||||
style = Text_style(
|
||||
size=style_data.get('style',{}).get('size', font_size),
|
||||
bold=style_data.get('style',{}).get('bold', False),
|
||||
italic=style_data.get('style',{}).get('italic', False),
|
||||
underline=style_data.get('style',{}).get('underline', False),
|
||||
color=hex_to_rgb(style_data.get('style',{}).get('color', font_color)),
|
||||
alpha=style_data.get('style',{}).get('alpha', font_alpha),
|
||||
align=style_data.get('style',{}).get('align', 1),
|
||||
vertical=style_data.get('style',{}).get('vertical', vertical),
|
||||
letter_spacing=style_data.get('style',{}).get('letter_spacing', 0),
|
||||
line_spacing=style_data.get('style',{}).get('line_spacing', 0)
|
||||
)
|
||||
|
||||
# 创建描边(如果有)
|
||||
border = None
|
||||
if style_data.get('border',{}).get('width', 0) > 0:
|
||||
border = Text_border(
|
||||
alpha=style_data.get('border',{}).get('alpha', border_alpha),
|
||||
color=hex_to_rgb(style_data.get('border',{}).get('color', border_color)),
|
||||
width=style_data.get('border',{}).get('width', border_width)
|
||||
)
|
||||
|
||||
# 创建样式范围对象
|
||||
style_range = TextStyleRange(
|
||||
start=start_pos,
|
||||
end=end_pos,
|
||||
style=style,
|
||||
border=border,
|
||||
font_str=style_data.get('font', font)
|
||||
)
|
||||
|
||||
text_styles.append(style_range)
|
||||
|
||||
result = {
|
||||
"success": False,
|
||||
"output": "",
|
||||
@@ -397,6 +454,17 @@ def add_text():
|
||||
background_color=background_color,
|
||||
background_style=background_style,
|
||||
background_alpha=background_alpha,
|
||||
background_round_radius=background_round_radius,
|
||||
background_height=background_height,
|
||||
background_width=background_width,
|
||||
background_horizontal_offset=background_horizontal_offset,
|
||||
background_vertical_offset=background_vertical_offset,
|
||||
shadow_enabled=shadow_enabled,
|
||||
shadow_alpha=shadow_alpha,
|
||||
shadow_angle=shadow_angle,
|
||||
shadow_color=shadow_color,
|
||||
shadow_distance=shadow_distance,
|
||||
shadow_smoothing=shadow_smoothing,
|
||||
bubble_effect_id=bubble_effect_id,
|
||||
bubble_resource_id=bubble_resource_id,
|
||||
effect_effect_id=effect_effect_id,
|
||||
@@ -407,7 +475,8 @@ def add_text():
|
||||
width=width,
|
||||
height=height,
|
||||
fixed_width=fixed_width,
|
||||
fixed_height=fixed_height
|
||||
fixed_height=fixed_height,
|
||||
text_styles = text_styles
|
||||
)
|
||||
|
||||
result["success"] = True
|
||||
|
||||
Reference in New Issue
Block a user