Python函数
-
根据提供的URL获取文件的相关信息
def get_file_info(file_url): """ 根据提供的URL获取文件的相关信息。 参数:file_url (str): 文件的网络地址。 返回:dict: 包含文件名、后缀名、内容类型和文件大小等信息的字典;如果失败则返回None。 """ data = dict() if not file_url: return return_dict(400, "file_url参数不能为空") try: # 发送HEAD请求以获取文件信息,而不下载整个文件。allow_redirects=True确保跟随重定向。 response = requests.head(file_url,
-
文本转mp3
def text_to_mp3(text): """ 文本转mp3 参数: text (str): 要转换的文字 返回: str: mp3文件路径 """ output_file = None # 内部定义异步函数 async def _amain(): nonlocal output_file VOICE = "zh-CN-YunxiNeural" # zh-CN-YunxiNeural zh-CN-XiaoxiaoNeural RATE = "+30%" # 调整语速 communicate = edge_tts.Communicate(text, VOICE, rate=RATE) #
-
将URL转换为二维码,并返回Base64编码的字符串
def url_to_qr_base64(url): """ 将URL转换为二维码,并返回Base64编码的字符串。 参数: url (str): 您想要编码成二维码的URL。 返回: str: Base64编码的二维码图片字符串。 或 None: 如果发生错误。 """ if not url: return return_dict(400, "url参数不能为空") try: # 创建QRCode对象 qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, bo
-
将Markdown内容转换为HTML
def markdown_to_html(markdown_content): """ 将Markdown内容转换为HTML。 参数: markdown_content (str): Markdown格式的内容字符串。 返回: str: 转换后的HTML格式的内容。 """ if not markdown_content: return return_dict(400, "markdown_content参数不能为空") try: # 使用markdown.markdown()方法进行转换 html_content = markdown.markdown(markdown_content) r
-
将HTML内容转换为Markdown格式
def html_to_markdown(html_content): """ 将HTML内容转换为Markdown格式。 参数: html_content (str): HTML格式的内容字符串。 返回: str: 转换后的Markdown格式的内容。 """ if not html_content: return return_dict(400, "html_content参数不能为空") try: h = html2text.HTML2Text() # 可选配置:调整输出格式 h.ignore_links = False # 如果为True,则链接会被忽略 h.ignore_images
-
生成图片
from PIL import Image, ImageColor, ImageDraw, ImageFont, ImageFilterdef create_image_with_text(size, color, text, font_path, font_size, text_color, shadow_color, output_path): """ Create a new image of specified size and color with centered text that has a border and shadow. :param size: A tuple con