python将图片文件转换成base64编码,,在网页里调用图片除了可以
python将图片文件转换成base64编码,,在网页里调用图片除了可以
在网页里调用图片除了可以直接给定图片路径外,还可以使用base64编码,下面的python代码可以将图片转换成base64编码
import base64f=open(r'c:\sharejs.jpg','rb') #二进制方式打开图文件ls_f=base64.b64encode(f.read()) #读取文件内容,转换为base64编码f.close()
调用方法javascript<imgsrc="data:image/bmp;base64,Qk0eAgAAAAAAALYAAAAoAAAAEgAAABIAAAABAAgAAAAAAAAAAA DEDgAAxA4AACAAAAAgAAAAFSph/ySn4f8jRGP/mt70/zg1M/9DqMr/YWJg/yZqtf8EAwP/Xouz/5O qpP81Vn7/O4ut/xQqQP8TUJL/TmaU/y9ylv8nWKH/g3Z1/x3d9v+JvNj/LCYk/yQcGf8Nb7T/HUKV /w0bJ/8XW7L/YNT7/7b1/P+Niof/I43F/////wAfFhYVFhUWFhYVFRUVFhUWFR8AABYCBwcYARgJC wQNDQICDQ0NBAAABAIaEQcHCwsNDQICBA0NDQIEAAAEAgcHHg4CCw4eFAIPAg0NAgQAAAQLBwceDg sQEQMJHh4GDQ0CBAAAFQsaGgcRDwULCw8UCQ0CDQsEAAAEAAcREQ4LCQEXDgAAAQIZEAQAABUCGAc RGAAJAxsbDAsKAhkQBAAAFQwYGAcHAAMDAxQUFAodDQIVAAAWHgEYGB4YAwMDHBwDCgYNDRUAABUQ AQEYBx4RFBQCFA8CBAACFQAABAgeAR4RAREZAAAJFA4ADQsVAAAECBkBAR4FHhEFHBwUCgoCAhUAA BUICB4eHgEHHBwcHAMUCgICFQAAFQgIDQEeEwEPAwMUCQkAAgwWAAACCAgIAQETExoAGhcXHg4TGR UAABUGFggZDAUFBQwMEBAMBQ8EBgAAHwQKEhISEhISEhIdEhISHRIfAAA=" />
相关内容
- 整数中1出现的次数(从1到n整数中1出现的次数),n整
- Python初学小试,python小试,None
- python的设计模式,python设计模式,# encoding=u
- 双击更新所有已安装的python模块,双击更新python模块
- 一个python自定义的加密解密函数,python加密解密,一个
- python 3个文件合并成3列.py,python.py,"""python 3个
- Windows下Python获取磁盘空闲空间并写入日志,python空闲
- monkeyrunner 代码示例,monkeyrunner示例,'''from com.
- python获取本机网卡的mac地址,python获取网卡mac,python获取
- programming python 之tkinter初学,pythontkinter,#!/usr/bin/e
评论关闭