推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
sdjl
V2EX  ›  Python

python 如果根据二进制图片数据得到图片类型?

  •  
  •   sdjl · Jan 6, 2013 · 4537 views
    This topic created in 5016 days ago, the information mentioned may be changed or developed.
    比如有d变量保存了post到服务器的二进制图片, 服务器需要检测是否为图片以及图片类型

    除了使用magic库以外 还有什么办法? 比如用mimetypes?
    5 replies  •  1970-01-01 08:00:00 +08:00
    Livid
        1
    Livid  
    MOD
    PRO
       Jan 6, 2013
    man file
    cute
        2
    cute  
       Jan 6, 2013   ❤️ 2
    import imghdr
    imgtype = imghdr.what('/tmp/bass.gif')
    imgtype = imghdr.what(None, data)
    luztak
        3
    luztak  
       Jan 6, 2013
    89 50 4e 47 0d 0a 1a 0a
    png文件头
    这两天看这个看得头疼
    sdjl
        4
    sdjl  
    OP
       Jan 6, 2013
    @cute imghdr.what(None, data) 正解! 感谢
    yemoluo
        5
    yemoluo  
       Jan 6, 2013
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2314 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:34 · PVG 09:34 · LAX 18:34 · JFK 21:34
    ♥ Do have faith in what you're doing.