美文网首页
python实现 图片jpg格式和base64格式互转

python实现 图片jpg格式和base64格式互转

作者: feitry | 来源:发表于2021-04-27 15:00 被阅读0次

    不想说啥啦,直接上代码,这里我进行的运行时macOS 10.15,python是3.9

    import base64
    # base64 数据读取图片 ok
    
    if __name__ == "__main__":
        dir = '/Users/admin/Desktop/1.jpg'
        basef = open(dir.split('.')[0] + '_base64.txt', 'w')
        with open(dir, 'rb') as f:
            base64_data = base64.b64encode(f.read())
            s = base64_data.decode()
            data = 'data:image/jpeg;base64,%s' % s
            print(data)
            basef.write(data)
        basef.close()
    
    # base64 数据读取图片 ok
    image_path = '/Users/admin/Desktop/1.jpg'
    with open(image_path, 'rb') as f:
        image = f.read()
        image_base64 = str(base64.b64encode(image), encoding='utf-8')
        print(image_base64)
    # base64 保存图片 ok
    
    import os,time
    # 前端上传的base64,存放在django的媒体文件库中
    avatar_url = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBMRXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAi6ADAAQAAAABAAAAiwAAAAD/wAARCACLAIsDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nz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ar_url.split(';base64,')[1]
        data = base64.b64decode(b64_data)
        image_url = 'image%s.jpg' % int(time.time())
        with open(image_url, 'wb') as f:
            f.write(data)
    #       # 截取media路径,存放在字段中
    #         image_url = image_url.split("project_name")[1].replace('\\', '/')[1:]
            # user对象
            # user.avatar_url = image_url
    

    相关文章

      网友评论

          本文标题:python实现 图片jpg格式和base64格式互转

          本文链接:https://www.haomeiwen.com/subject/ieaurltx.html