[python]简单获取图片 MIME 类型及解码字符串

获取图片 MIME 类型

https://github.com/mozillazg/image-mime

使用

>>> with open('test', 'rb') as f:
...     print get_image_mime(f.read())
...
image/png
>>>
>>> with open('test.exe', 'rb') as f:
...     print get_image_mime(f.read())
...
application/octet-stream

转换未知编码的字符串为 Unicode 字符串

https://gist.github.com/3870483

使用

>>> decode_('\xc4\xe3')
u'\u4f60'
>>> decode_('\xe4\xbd\xa0')
u'\u4f60'
>>>

Base64 编码、解码工具 Base64.exe

使用说明:

Base64 [options] [input file] [output file]
 options are:
 -i <filename> input file (default: stdin)
 -o <filename> output file (default: stdout)
 -e            encode binary to Base64 (default)
 -d            decode Base64 to binary
 -n <n>        encode n characters per line (0:no line breaks,default:64)
 -E <STRING>   encode and put -----BEGIN/END <STRING>----- around output
 --            indicate end of options
Call as b642bin to preselect decoding
(c) Matthias Gaertner 2002 - v1.00

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

下载:Base64.exe

实例 : 继续阅读

Base64 编码、解码工具 Base64.exe

使用说明:

Base64 [options] [input file] [output file]
options are:
-i <filename> input file (default: stdin)
-o <filename> output file (default: stdout)
-e            encode binary to Base64 (default)
-d            decode Base64 to binary
-n <n>        encode n characters per line (0:no line breaks,default:64)
-E <STRING>   encode and put -----BEGIN/END <STRING>----- around output
--            indicate end of options
Call as b642bin to preselect decoding
(c) Matthias Gaertner 2002 - v1.00

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

下载:Base64.exe 实例 :

  Base64.exe and test.txt

原始内容:

test.txt

编码:

encode

encode after

编码后:

test_encode.txt

解码:

decode decode after

解码后:

test_decode.txt

原始文件内容:

test.txt