• base 64转码PYTHON


    import os, base64
    
    # 图片装换
    
    # 将读取的二进制文件转换为base64字符串
    bs64_str = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAgAFoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD2/WNZstCsftd87LGTtUKpYs2CQo9zg9cD3qlpnim31O4giGn6lbLcDMMtzb7Y5ON2AwJGdoJ+grkfHnnz+ONIto/LkykXlxT5MRZpCPmHocAH1Aq2dV1nQ/HlhY6pqbX9tPH5a7IhGP3jABiowMhkxkk4UnHJxW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nnlt3QnttzztzXY+D4YrLw3BpkcaRNpzPZyKqhSzIxHmFf4TIMS49JAcnOTu1kPDLY+JIriCN2ttQXyrhUUkJKilklOOACoZGY5JIhA4FGwKKWqJde0651fR57C1vVtDOpjklMPmHYRhgBkYJ6Z9M98EcxL8NbVLDSUsL77Jf6e/mfbPsysZWzuyw4zggbck4HHPWu5orOdGE3eSG0mMiEgiQSsryBRvZF2gnuQMnA9sn60+iitRn//Z'
    # 打印图像转换base64格式的字符串,type结果为<class 'bytes'>
    # 前端上传的base64,存放在django的媒体文件库中
    b64_data =bs64_str.split(';base64,')[1]
    
    print(b64_data)
    data = base64.b64decode(b64_data)
    with open("yzm.jpg", 'wb') as f:
        f.write(data)

     安装PILLOW  直接显示

    # -*- encode:utf-8 -*-
    import os, base64
    from PIL import Image,ImageGrab
    from io import BytesIO
    # 图片装换
    
    # 将读取的二进制文件转换为base64字符串
    bs64_str = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAgAFoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAEC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QC545O5tx+cg4zWVStGlJRet9rdX28jRysewabrFnq3mmyMzxx4xK1vIkcgOcNG7KFkU4zuQkYIOeRm/TIo1hiSJSxVFCguxY4HqTyT7nmn1q7dCjH1/wAO2+vxQF5pre5tiXt54mwUY+3cZCnseOCKwJPDs9n4q0fUtS1I6lcT3XkjfAEVFWCZxgAkZDIpGMYOT1Oa7esnxBDLJZWzwRu88V9aupjUlkXzkDkY5A8suD/sls8ZpKEXLUaSbNavPdW+G19eeOpvFem+I/7Pu32+Wv2FZdmIhGfvNg5APbvXoVFJq5EoKW5wdr8NBPria54g1681XU4mHlyCNIY0QDgBADtIO47lIIJyMN81bun+DNC0i3a3023uLKFm3tHbXs0alsAZIVwM4A59q36KLLYFCK2R5jqHwmvdWdYdQ8XXN1ZLMHCzWivceWDwnnlt3QnttzztzXY+D4YrLw3BpkcaRNpzPZyKqhSzIxHmFf4TIMS49JAcnOTu1kPDLY+JIriCN2ttQXyrhUUkJKilklOOACoZGY5JIhA4FGwKKWqJde0651fR57C1vVtDOpjklMPmHYRhgBkYJ6Z9M98EcxL8NbVLDSUsL77Jf6e/mfbPsysZWzuyw4zggbck4HHPWu5orOdGE3eSG0mMiEgiQSsryBRvZF2gnuQMnA9sn60+iitRn//Z'
    # 打印图像转换base64格式的字符串,type结果为<class 'bytes'>
    # 前端上传的base64,存放在django的媒体文件库中
    b64_data =bs64_str.split(';base64,')[1]
    
    print(b64_data)
    data = base64.b64decode(b64_data)
    im=Image.open(BytesIO(data))
    im.show()
  • 相关阅读:
    senrty 配置Email
    pip安装使用详解
    C_FORCE_ROOT linux环境变量设置
    Supervisord管理
    解决外部机器通过VM内ubuntu IP 无法访问vm内web服务的问题
    C# 使用Nlog记录日志到数据库 使用LogEventInfo类获取,命名空间名称、类名、方法名
    godaddy.com 注册域名 买卖域名
    vue-15-vuex-store的用法
    vue-14-less 语法的使用
    vue-13-swiper组件的使用
  • 原文地址:https://www.cnblogs.com/xupanfeng/p/11808496.html
Copyright © 2020-2023  润新知