def detect_picture(file): """ 检测图片的类型 :param file: 路径 :return: """ # 读取前 32 个字节 data = open(file, "rb").read(32) if data[6:10] in (b'JFIF', b'Exif'): return 'jpeg' elif data.startswith(b'211PNG
32
'): return 'png' elif data[:6] in (b'GIF87a', b'GIF89a'): return 'gif' elif data[:2] in (b'MM', b'II'): return 'tiff' elif data.startswith(b'