blowjob sex videos tubeshere.mobi pron china
indian sex prom video wetwap.info indian wife nude ass
bur ki chudai hindi iwanktv.info xxxx porn video
college gril sex nuporn.mobi sex videos school
anti carnapping eteleserye.com the broken marriage vow may 9 2022
jbl serial number checker freeteleseryetv.net broken marriage vow april 12 full episode
comelec antipolo pinoyteleseryechannel.com abot kamay na pangarap episode 29 full episode
قص سكس محارم porndotcom.org العنتيل sex
boui video songs indiandesiclips.com big boob sex videos
خالد يوسف وعلا غانم parabg.com سكيسس بنات
indian milfs pornhan.mobi xxx deepika movie
levi ackerman hentai onhentai.com simca hentai
munmun dutta porn freetubemovs.com cham cham video
hot indian sex story xxx-tube-list.info whatsapp comedy videos
bangali xxx.com dampxxx.org xvideo sleeping

写了一个python方法将图片url转换成带前缀的base64

2023年11月8日

开发api的时候经常需要把图片url转base64,专门写了一个方法

def url_to_base64_with_prefix(image_url):
    # 发送 GET 请求来获取图片
    response = requests.get(image_url)
    if response.status_code == 200:
        # 获取图片的二进制数据
        image_data = response.content
        # 通过二进制数据来确定图片格式
        image_format = Image.open(BytesIO(image_data)).format.lower()
        # 将图片数据转换成Base64编码
        base64_image = base64.b64encode(image_data).decode('utf-8')
        # 根据图片格式来添加相应的前缀
        if image_format == "jpeg":
            base64_image_with_prefix = f"data:image/jpeg;base64,{base64_image}"
        elif image_format == "png":
            base64_image_with_prefix = f"data:image/png;base64,{base64_image}"
        elif image_format == "gif":
            base64_image_with_prefix = f"data:image/gif;base64,{base64_image}"
        elif image_format == "bmp":
            base64_image_with_prefix = f"data:image/bmp;base64,{base64_image}"
        else:
            # 如果不是常见的格式,可以使用通用的"data:image;base64,"前缀
            base64_image_with_prefix = f"data:image/{image_format};base64,{base64_image}"

        return base64_image_with_prefix
    else:
        print("无法下载图片,状态码: ", response.status_code)
        return None

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注