/usr/lib/python2.7/dist-packages/sphinx/util/images.py is in python-sphinx 1.4.9-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # -*- coding: utf-8 -*-
"""
sphinx.util.images
~~~~~~~~~~~~~~~~~~
Image utility functions for Sphinx.
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import imghdr
import imagesize
from os import path
try:
from PIL import Image # check for the Python Imaging Library
except ImportError:
try:
import Image
except ImportError:
Image = None
mime_suffixes = {
'.pdf': 'application/pdf',
'.svg': 'image/svg+xml',
}
def get_image_size(filename):
try:
size = imagesize.get(filename)
if size[0] == -1:
size = None
if size is None and Image: # fallback to PIL
im = Image.open(filename)
size = im.size
try:
im.fp.close()
except Exception:
pass
return size
except:
return None
def guess_mimetype(filename):
_, ext = path.splitext(filename)
if ext in mime_suffixes:
return mime_suffixes[ext]
else:
with open(filename, 'rb') as f:
imgtype = imghdr.what(f)
if imgtype:
return 'image/' + imgtype
return None
|