Linux iad1-shared-b7-18 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
Apache
: 67.205.6.31 | : 216.73.216.47
Cant Read [ /etc/named.conf ]
8.2.29
fernandoquevedo
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
usr /
lib /
python3 /
dist-packages /
[ HOME SHELL ]
Name
Size
Permission
Action
Babel-2.8.0.egg-info
[ DIR ]
drwxr-xr-x
CommandNotFound
[ DIR ]
drwxr-xr-x
DistUpgrade
[ DIR ]
drwxr-xr-x
Django-3.2.12.egg-info
[ DIR ]
drwxr-xr-x
Genshi-0.7.6.egg-info
[ DIR ]
drwxr-xr-x
HweSupportStatus
[ DIR ]
drwxr-xr-x
Jinja2-3.0.3.egg-info
[ DIR ]
drwxr-xr-x
MarkupSafe-2.0.1.egg-info
[ DIR ]
drwxr-xr-x
MySQLdb
[ DIR ]
drwxr-xr-x
OpenSSL
[ DIR ]
drwxr-xr-x
PyGObject-3.42.1.egg-info
[ DIR ]
drwxr-xr-x
PyGreSQL-5.1.2.egg-info
[ DIR ]
drwxr-xr-x
PyJWT-2.3.0.egg-info
[ DIR ]
drwxr-xr-x
PyYAML-5.4.1.egg-info
[ DIR ]
drwxr-xr-x
Pygments-2.11.2.egg-info
[ DIR ]
drwxr-xr-x
S3
[ DIR ]
drwxr-xr-x
SecretStorage-3.3.1.egg-info
[ DIR ]
drwxr-xr-x
Sphinx-4.3.2.egg-info
[ DIR ]
drwxr-xr-x
Trac-1.5.3.egg-info
[ DIR ]
drwxr-xr-x
UpdateManager
[ DIR ]
drwxr-xr-x
__pycache__
[ DIR ]
drwxr-xr-x
_distutils_hack
[ DIR ]
drwxr-xr-x
_yaml
[ DIR ]
drwxr-xr-x
alabaster
[ DIR ]
drwxr-xr-x
alabaster-0.7.12.egg-info
[ DIR ]
drwxr-xr-x
apport
[ DIR ]
drwxr-xr-x
apt
[ DIR ]
drwxr-xr-x
apt_inst-stubs
[ DIR ]
drwxr-xr-x
apt_pkg-stubs
[ DIR ]
drwxr-xr-x
aptsources
[ DIR ]
drwxr-xr-x
asgiref
[ DIR ]
drwxr-xr-x
asgiref-3.5.0.egg-info
[ DIR ]
drwxr-xr-x
attr
[ DIR ]
drwxr-xr-x
attrs-21.2.0.egg-info
[ DIR ]
drwxr-xr-x
awscli
[ DIR ]
drwxr-xr-x
awscli-1.22.34.egg-info
[ DIR ]
drwxr-xr-x
babel
[ DIR ]
drwxr-xr-x
blinker
[ DIR ]
drwxr-xr-x
boto
[ DIR ]
drwxr-xr-x
boto-2.49.0.egg-info
[ DIR ]
drwxr-xr-x
botocore
[ DIR ]
drwxr-xr-x
botocore-1.23.34.egg-info
[ DIR ]
drwxr-xr-x
certifi
[ DIR ]
drwxr-xr-x
certifi-2020.6.20.egg-info
[ DIR ]
drwxr-xr-x
chardet
[ DIR ]
drwxr-xr-x
chardet-4.0.0.egg-info
[ DIR ]
drwxr-xr-x
colorama
[ DIR ]
drwxr-xr-x
colorama-0.4.4.egg-info
[ DIR ]
drwxr-xr-x
configobj-5.0.6.egg-info
[ DIR ]
drwxr-xr-x
cryptography
[ DIR ]
drwxr-xr-x
cryptography-3.4.8.egg-info
[ DIR ]
drwxr-xr-x
curl
[ DIR ]
drwxr-xr-x
dateutil
[ DIR ]
drwxr-xr-x
dbus
[ DIR ]
drwxr-xr-x
dbus_python-1.2.18.egg-info
[ DIR ]
drwxr-xr-x
debian
[ DIR ]
drwxr-xr-x
debian_bundle
[ DIR ]
drwxr-xr-x
devscripts
[ DIR ]
drwxr-xr-x
devscripts-2.22.1ubuntu1.egg-i...
[ DIR ]
drwxr-xr-x
distlib
[ DIR ]
drwxr-xr-x
distlib-0.3.4.egg-info
[ DIR ]
drwxr-xr-x
distro
[ DIR ]
drwxr-xr-x
distro-1.7.0.egg-info
[ DIR ]
drwxr-xr-x
distro_info-1.1+ubuntu0.2.egg-...
[ DIR ]
drwxr-xr-x
django
[ DIR ]
drwxr-xr-x
docutils
[ DIR ]
drwxr-xr-x
docutils-0.17.1.egg-info
[ DIR ]
drwxr-xr-x
duplicity
[ DIR ]
drwxr-xr-x
duplicity-0.8.21.egg-info
[ DIR ]
drwxr-xr-x
fail2ban
[ DIR ]
drwxr-xr-x
fail2ban-0.11.2.egg-info
[ DIR ]
drwxr-xr-x
fasteners
[ DIR ]
drwxr-xr-x
fasteners-0.14.1.egg-info
[ DIR ]
drwxr-xr-x
filelock
[ DIR ]
drwxr-xr-x
filelock-3.6.0.egg-info
[ DIR ]
drwxr-xr-x
future
[ DIR ]
drwxr-xr-x
future-0.18.2.egg-info
[ DIR ]
drwxr-xr-x
genshi
[ DIR ]
drwxr-xr-x
gi
[ DIR ]
drwxr-xr-x
hgdemandimport
[ DIR ]
drwxr-xr-x
hgext
[ DIR ]
drwxr-xr-x
hgext3rd
[ DIR ]
drwxr-xr-x
httplib2
[ DIR ]
drwxr-xr-x
httplib2-0.20.2.egg-info
[ DIR ]
drwxr-xr-x
idna
[ DIR ]
drwxr-xr-x
idna-3.3.egg-info
[ DIR ]
drwxr-xr-x
imagesize-1.3.0.egg-info
[ DIR ]
drwxr-xr-x
importlib_metadata
[ DIR ]
drwxr-xr-x
importlib_metadata-4.6.4.egg-i...
[ DIR ]
drwxr-xr-x
iotop
[ DIR ]
drwxr-xr-x
janitor
[ DIR ]
drwxr-xr-x
jeepney
[ DIR ]
drwxr-xr-x
jeepney-0.7.1.dist-info
[ DIR ]
drwxr-xr-x
jinja2
[ DIR ]
drwxr-xr-x
jmespath
[ DIR ]
drwxr-xr-x
jmespath-0.10.0.egg-info
[ DIR ]
drwxr-xr-x
jsonpatch-1.32.egg-info
[ DIR ]
drwxr-xr-x
jsonpointer-2.0.egg-info
[ DIR ]
drwxr-xr-x
jsonschema
[ DIR ]
drwxr-xr-x
jsonschema-3.2.0.egg-info
[ DIR ]
drwxr-xr-x
jwt
[ DIR ]
drwxr-xr-x
keyring
[ DIR ]
drwxr-xr-x
keyring-23.5.0.egg-info
[ DIR ]
drwxr-xr-x
launchpadlib
[ DIR ]
drwxr-xr-x
launchpadlib-1.10.16.egg-info
[ DIR ]
drwxr-xr-x
lazr
[ DIR ]
drwxr-xr-x
lazr.restfulclient-0.14.4.egg-...
[ DIR ]
drwxr-xr-x
lazr.uri-1.0.6.egg-info
[ DIR ]
drwxr-xr-x
libfuturize
[ DIR ]
drwxr-xr-x
libpasteurize
[ DIR ]
drwxr-xr-x
lockfile
[ DIR ]
drwxr-xr-x
lockfile-0.12.2.egg-info
[ DIR ]
drwxr-xr-x
magic
[ DIR ]
drwxr-xr-x
markupsafe
[ DIR ]
drwxr-xr-x
mercurial
[ DIR ]
drwxr-xr-x
monotonic-1.6.egg-info
[ DIR ]
drwxr-xr-x
more_itertools
[ DIR ]
drwxr-xr-x
more_itertools-8.10.0.egg-info
[ DIR ]
drwxr-xr-x
mysqlclient-1.4.6.egg-info
[ DIR ]
drwxr-xr-x
netifaces-0.11.0.egg-info
[ DIR ]
drwxr-xr-x
numpy
[ DIR ]
drwxr-xr-x
numpy-1.21.5.egg-info
[ DIR ]
drwxr-xr-x
oauthlib
[ DIR ]
drwxr-xr-x
oauthlib-3.2.0.egg-info
[ DIR ]
drwxr-xr-x
packaging
[ DIR ]
drwxr-xr-x
packaging-21.3.egg-info
[ DIR ]
drwxr-xr-x
past
[ DIR ]
drwxr-xr-x
pexpect
[ DIR ]
drwxr-xr-x
pip
[ DIR ]
drwxr-xr-x
pip-22.0.2.dist-info
[ DIR ]
drwxr-xr-x
pkg_resources
[ DIR ]
drwxr-xr-x
platformdirs
[ DIR ]
drwxr-xr-x
platformdirs-2.5.1.dist-info
[ DIR ]
drwxr-xr-x
psycopg2
[ DIR ]
drwxr-xr-x
psycopg2-2.9.2.egg-info
[ DIR ]
drwxr-xr-x
ptyprocess
[ DIR ]
drwxr-xr-x
ptyprocess-0.7.0.dist-info
[ DIR ]
drwxr-xr-x
pyOpenSSL-21.0.0.egg-info
[ DIR ]
drwxr-xr-x
pyasn1
[ DIR ]
drwxr-xr-x
pyasn1-0.4.8.egg-info
[ DIR ]
drwxr-xr-x
pycurl-7.44.1.egg-info
[ DIR ]
drwxr-xr-x
pygments
[ DIR ]
drwxr-xr-x
pygtkcompat
[ DIR ]
drwxr-xr-x
pyparsing-2.4.7.egg-info
[ DIR ]
drwxr-xr-x
pyrsistent
[ DIR ]
drwxr-xr-x
pyrsistent-0.18.1.egg-info
[ DIR ]
drwxr-xr-x
pyserial-3.5.egg-info
[ DIR ]
drwxr-xr-x
pysvn
[ DIR ]
drwxr-xr-x
pysvn-1.9.15.egg-info
[ DIR ]
drwxr-xr-x
python_apt-2.4.0+ubuntu4.1.egg...
[ DIR ]
drwxr-xr-x
python_dateutil-2.8.1.egg-info
[ DIR ]
drwxr-xr-x
python_debian-0.1.43+ubuntu1.1...
[ DIR ]
drwxr-xr-x
python_magic-0.4.24.egg-info
[ DIR ]
drwxr-xr-x
pytz
[ DIR ]
drwxr-xr-x
pytz-2022.1.egg-info
[ DIR ]
drwxr-xr-x
requests
[ DIR ]
drwxr-xr-x
requests-2.25.1.egg-info
[ DIR ]
drwxr-xr-x
roman-3.3.egg-info
[ DIR ]
drwxr-xr-x
rsa
[ DIR ]
drwxr-xr-x
rsa-4.8.egg-info
[ DIR ]
drwxr-xr-x
s3cmd-2.2.0.egg-info
[ DIR ]
drwxr-xr-x
s3transfer
[ DIR ]
drwxr-xr-x
s3transfer-0.5.0.egg-info
[ DIR ]
drwxr-xr-x
secretstorage
[ DIR ]
drwxr-xr-x
serial
[ DIR ]
drwxr-xr-x
setuptools
[ DIR ]
drwxr-xr-x
setuptools-59.6.0.egg-info
[ DIR ]
drwxr-xr-x
simplejson
[ DIR ]
drwxr-xr-x
simplejson-3.17.6.egg-info
[ DIR ]
drwxr-xr-x
six-1.16.0.egg-info
[ DIR ]
drwxr-xr-x
snowballstemmer
[ DIR ]
drwxr-xr-x
snowballstemmer-2.2.0.egg-info
[ DIR ]
drwxr-xr-x
softwareproperties
[ DIR ]
drwxr-xr-x
sos
[ DIR ]
drwxr-xr-x
sos-4.10.2.egg-info
[ DIR ]
drwxr-xr-x
sphinx
[ DIR ]
drwxr-xr-x
sqlparse
[ DIR ]
drwxr-xr-x
sqlparse-0.4.2.egg-info
[ DIR ]
drwxr-xr-x
ssh_import_id
[ DIR ]
drwxr-xr-x
ssh_import_id-5.11.egg-info
[ DIR ]
drwxr-xr-x
systemd
[ DIR ]
drwxr-xr-x
trac
[ DIR ]
drwxr-xr-x
tracopt
[ DIR ]
drwxr-xr-x
twisted
[ DIR ]
drwxr-xr-x
uaclient
[ DIR ]
drwxr-xr-x
ubuntu_pro_client-8001.egg-inf...
[ DIR ]
drwxr-xr-x
ufw
[ DIR ]
drwxr-xr-x
unattended_upgrades-0.1.egg-in...
[ DIR ]
drwxr-xr-x
urllib3
[ DIR ]
drwxr-xr-x
urllib3-1.26.5.egg-info
[ DIR ]
drwxr-xr-x
virtualenv
[ DIR ]
drwxr-xr-x
virtualenv-20.13.0+ds.dist-inf...
[ DIR ]
drwxr-xr-x
wadllib
[ DIR ]
drwxr-xr-x
wadllib-1.3.6.egg-info
[ DIR ]
drwxr-xr-x
wheel
[ DIR ]
drwxr-xr-x
wheel-0.37.1.egg-info
[ DIR ]
drwxr-xr-x
xapian
[ DIR ]
drwxr-xr-x
yaml
[ DIR ]
drwxr-xr-x
zipp-1.0.0.egg-info
[ DIR ]
drwxr-xr-x
_cffi_backend.cpython-310-x86_...
189.91
KB
-rw-r--r--
_dbus_bindings.cpython-310-x86...
164.21
KB
-rw-r--r--
_dbus_glib_bindings.cpython-31...
22.5
KB
-rw-r--r--
_pg.cpython-310-x86_64-linux-g...
111.7
KB
-rw-r--r--
_pyrsistent_version.py
23
B
-rw-r--r--
_snack.cpython-310-x86_64-linu...
46.77
KB
-rw-r--r--
_version.py
21
B
-rw-r--r--
apport_python_hook.py
7.87
KB
-rw-r--r--
apt_inst.cpython-310-x86_64-li...
58.66
KB
-rw-r--r--
apt_pkg.cpython-310-x86_64-lin...
338.96
KB
-rw-r--r--
blinker-1.4.egg-info
3.81
KB
-rw-r--r--
command_not_found-0.3.egg-info
189
B
-rw-r--r--
configobj.py
87.51
KB
-rw-r--r--
deb822.py
273
B
-rw-r--r--
debconf.py
6.61
KB
-rw-r--r--
distro_info.py
12.23
KB
-rw-r--r--
drv_libxml2.py
15.02
KB
-rw-r--r--
imagesize.py
13.04
KB
-rw-r--r--
iotop-0.6.egg-info
348
B
-rw-r--r--
jsonpatch.py
28.14
KB
-rw-r--r--
jsonpointer.py
9.57
KB
-rw-r--r--
libxml2.py
338.19
KB
-rw-r--r--
libxml2mod.cpython-310-x86_64-...
427.55
KB
-rw-r--r--
lsb_release.py
14.55
KB
-rw-r--r--
mercurial-6.1.1-py3.10.egg-inf...
1.3
KB
-rw-r--r--
monotonic.py
7
KB
-rw-r--r--
netifaces.cpython-310-x86_64-l...
22.69
KB
-rw-r--r--
pexpect-4.8.0.egg-info
2.23
KB
-rw-r--r--
pg.py
99.81
KB
-rw-r--r--
pgdb.py
62.08
KB
-rw-r--r--
problem_report.py
26.24
KB
-rw-r--r--
pvectorc.cpython-310-x86_64-li...
36.67
KB
-rw-r--r--
pycurl.cpython-310-x86_64-linu...
140.6
KB
-rw-r--r--
pyparsing.py
266.96
KB
-rw-r--r--
roman.py
3.58
KB
-rw-r--r--
schedutils-0.6.egg-info
291
B
-rw-r--r--
schedutils.cpython-310-x86_64-...
14.78
KB
-rw-r--r--
six.py
33.74
KB
-rw-r--r--
snack.py
30.4
KB
-rw-r--r--
systemd_python-234.egg-info
586
B
-rw-r--r--
ufw-0.36.1.egg-info
263
B
-rw-r--r--
validate.py
46.14
KB
-rw-r--r--
zipp.py
6.75
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : imagesize.py
import io import os import re import struct from xml.etree import ElementTree _UNIT_KM = -3 _UNIT_100M = -2 _UNIT_10M = -1 _UNIT_1M = 0 _UNIT_10CM = 1 _UNIT_CM = 2 _UNIT_MM = 3 _UNIT_0_1MM = 4 _UNIT_0_01MM = 5 _UNIT_UM = 6 _UNIT_INCH = 6 _TIFF_TYPE_SIZES = { 1: 1, 2: 1, 3: 2, 4: 4, 5: 8, 6: 1, 7: 1, 8: 2, 9: 4, 10: 8, 11: 4, 12: 8, } def _convertToDPI(density, unit): if unit == _UNIT_KM: return int(density * 0.0000254 + 0.5) elif unit == _UNIT_100M: return int(density * 0.000254 + 0.5) elif unit == _UNIT_10M: return int(density * 0.00254 + 0.5) elif unit == _UNIT_1M: return int(density * 0.0254 + 0.5) elif unit == _UNIT_10CM: return int(density * 0.254 + 0.5) elif unit == _UNIT_CM: return int(density * 2.54 + 0.5) elif unit == _UNIT_MM: return int(density * 25.4 + 0.5) elif unit == _UNIT_0_1MM: return density * 254 elif unit == _UNIT_0_01MM: return density * 2540 elif unit == _UNIT_UM: return density * 25400 return density def _convertToPx(value): matched = re.match(r"(\d+(?:\.\d+)?)?([a-z]*)$", value) if not matched: raise ValueError("unknown length value: %s" % value) length, unit = matched.groups() if unit == "": return float(length) elif unit == "cm": return float(length) * 96 / 2.54 elif unit == "mm": return float(length) * 96 / 2.54 / 10 elif unit == "in": return float(length) * 96 elif unit == "pc": return float(length) * 96 / 6 elif unit == "pt": return float(length) * 96 / 6 elif unit == "px": return float(length) raise ValueError("unknown unit type: %s" % unit) def get(filepath): """ Return (width, height) for a given img file content no requirements :type filepath: Union[bytes, str, pathlib.Path] :rtype Tuple[int, int] """ height = -1 width = -1 if isinstance(filepath, io.BytesIO): # file-like object fhandle = filepath else: fhandle = open(filepath, 'rb') try: head = fhandle.read(24) size = len(head) # handle GIFs if size >= 10 and head[:6] in (b'GIF87a', b'GIF89a'): # Check to see if content_type is correct try: width, height = struct.unpack("<hh", head[6:10]) except struct.error: raise ValueError("Invalid GIF file") # see png edition spec bytes are below chunk length then and finally the elif size >= 24 and head.startswith(b'\211PNG\r\n\032\n') and head[12:16] == b'IHDR': try: width, height = struct.unpack(">LL", head[16:24]) except struct.error: raise ValueError("Invalid PNG file") # Maybe this is for an older PNG version. elif size >= 16 and head.startswith(b'\211PNG\r\n\032\n'): # Check to see if we have the right content type try: width, height = struct.unpack(">LL", head[8:16]) except struct.error: raise ValueError("Invalid PNG file") # handle JPEGs elif size >= 2 and head.startswith(b'\377\330'): try: fhandle.seek(0) # Read 0xff next size = 2 ftype = 0 while not 0xc0 <= ftype <= 0xcf or ftype in [0xc4, 0xc8, 0xcc]: fhandle.seek(size, 1) byte = fhandle.read(1) while ord(byte) == 0xff: byte = fhandle.read(1) ftype = ord(byte) size = struct.unpack('>H', fhandle.read(2))[0] - 2 # We are at a SOFn block fhandle.seek(1, 1) # Skip `precision' byte. height, width = struct.unpack('>HH', fhandle.read(4)) except (struct.error, TypeError): raise ValueError("Invalid JPEG file") # handle JPEG2000s elif size >= 12 and head.startswith(b'\x00\x00\x00\x0cjP \r\n\x87\n'): fhandle.seek(48) try: height, width = struct.unpack('>LL', fhandle.read(8)) except struct.error: raise ValueError("Invalid JPEG2000 file") # handle big endian TIFF elif size >= 8 and head.startswith(b"\x4d\x4d\x00\x2a"): offset = struct.unpack('>L', head[4:8])[0] fhandle.seek(offset) ifdsize = struct.unpack(">H", fhandle.read(2))[0] for i in range(ifdsize): tag, datatype, count, data = struct.unpack(">HHLL", fhandle.read(12)) if tag == 256: if datatype == 3: width = int(data / 65536) elif datatype == 4: width = data else: raise ValueError("Invalid TIFF file: width column data type should be SHORT/LONG.") elif tag == 257: if datatype == 3: height = int(data / 65536) elif datatype == 4: height = data else: raise ValueError("Invalid TIFF file: height column data type should be SHORT/LONG.") if width != -1 and height != -1: break if width == -1 or height == -1: raise ValueError("Invalid TIFF file: width and/or height IDS entries are missing.") elif size >= 8 and head.startswith(b"\x49\x49\x2a\x00"): offset = struct.unpack('<L', head[4:8])[0] fhandle.seek(offset) ifdsize = struct.unpack("<H", fhandle.read(2))[0] for i in range(ifdsize): tag, datatype, count, data = struct.unpack("<HHLL", fhandle.read(12)) if tag == 256: width = data elif tag == 257: height = data if width != -1 and height != -1: break if width == -1 or height == -1: raise ValueError("Invalid TIFF file: width and/or height IDS entries are missing.") # handle little endian BigTiff elif size >= 8 and head.startswith(b"\x49\x49\x2b\x00"): bytesize_offset = struct.unpack('<L', head[4:8])[0] if bytesize_offset != 8: raise ValueError('Invalid BigTIFF file: Expected offset to be 8, found {} instead.'.format(offset)) offset = struct.unpack('<Q', head[8:16])[0] fhandle.seek(offset) ifdsize = struct.unpack("<Q", fhandle.read(8))[0] for i in range(ifdsize): tag, datatype, count, data = struct.unpack("<HHQQ", fhandle.read(20)) if tag == 256: width = data elif tag == 257: height = data if width != -1 and height != -1: break if width == -1 or height == -1: raise ValueError("Invalid BigTIFF file: width and/or height IDS entries are missing.") # handle SVGs elif size >= 5 and (head.startswith(b'<?xml') or head.startswith(b'<svg')): fhandle.seek(0) data = fhandle.read(1024) try: data = data.decode('utf-8') width = re.search(r'[^-]width="(.*?)"', data).group(1) height = re.search(r'[^-]height="(.*?)"', data).group(1) except Exception: raise ValueError("Invalid SVG file") width = _convertToPx(width) height = _convertToPx(height) # handle Netpbm elif head[:1] == b"P" and head[1:2] in b"123456": fhandle.seek(2) sizes = [] while True: next_chr = fhandle.read(1) if next_chr.isspace(): continue if next_chr == b"": raise ValueError("Invalid Netpbm file") if next_chr == b"#": fhandle.readline() continue if not next_chr.isdigit(): raise ValueError("Invalid character found on Netpbm file") size = next_chr next_chr = fhandle.read(1) while next_chr.isdigit(): size += next_chr next_chr = fhandle.read(1) sizes.append(int(size)) if len(sizes) == 2: break fhandle.seek(-1, os.SEEK_CUR) width, height = sizes finally: fhandle.close() return width, height def getDPI(filepath): """ Return (x DPI, y DPI) for a given img file content no requirements :type filepath: Union[bytes, str, pathlib.Path] :rtype Tuple[int, int] """ xDPI = -1 yDPI = -1 if not isinstance(filepath, bytes): filepath = str(filepath) with open(filepath, 'rb') as fhandle: head = fhandle.read(24) size = len(head) # handle GIFs # GIFs doesn't have density if size >= 10 and head[:6] in (b'GIF87a', b'GIF89a'): pass # see png edition spec bytes are below chunk length then and finally the elif size >= 24 and head.startswith(b'\211PNG\r\n\032\n'): chunkOffset = 8 chunk = head[8:] while True: chunkType = chunk[4:8] if chunkType == b'pHYs': try: xDensity, yDensity, unit = struct.unpack(">LLB", chunk[8:]) except struct.error: raise ValueError("Invalid PNG file") if unit: xDPI = _convertToDPI(xDensity, _UNIT_1M) yDPI = _convertToDPI(yDensity, _UNIT_1M) else: # no unit xDPI = xDensity yDPI = yDensity break elif chunkType == b'IDAT': break else: try: dataSize, = struct.unpack(">L", chunk[0:4]) except struct.error: raise ValueError("Invalid PNG file") chunkOffset += dataSize + 12 fhandle.seek(chunkOffset) chunk = fhandle.read(17) # handle JPEGs elif size >= 2 and head.startswith(b'\377\330'): try: fhandle.seek(0) # Read 0xff next size = 2 ftype = 0 while not 0xc0 <= ftype <= 0xcf: if ftype == 0xe0: # APP0 marker fhandle.seek(7, 1) unit, xDensity, yDensity = struct.unpack(">BHH", fhandle.read(5)) if unit == 1 or unit == 0: xDPI = xDensity yDPI = yDensity elif unit == 2: xDPI = _convertToDPI(xDensity, _UNIT_CM) yDPI = _convertToDPI(yDensity, _UNIT_CM) break fhandle.seek(size, 1) byte = fhandle.read(1) while ord(byte) == 0xff: byte = fhandle.read(1) ftype = ord(byte) size = struct.unpack('>H', fhandle.read(2))[0] - 2 except struct.error: raise ValueError("Invalid JPEG file") # handle JPEG2000s elif size >= 12 and head.startswith(b'\x00\x00\x00\x0cjP \r\n\x87\n'): fhandle.seek(32) # skip JP2 image header box headerSize = struct.unpack('>L', fhandle.read(4))[0] - 8 fhandle.seek(4, 1) foundResBox = False try: while headerSize > 0: boxHeader = fhandle.read(8) boxType = boxHeader[4:] if boxType == b'res ': # find resolution super box foundResBox = True headerSize -= 8 break boxSize, = struct.unpack('>L', boxHeader[:4]) fhandle.seek(boxSize - 8, 1) headerSize -= boxSize if foundResBox: while headerSize > 0: boxHeader = fhandle.read(8) boxType = boxHeader[4:] if boxType == b'resd': # Display resolution box yDensity, xDensity, yUnit, xUnit = struct.unpack(">HHBB", fhandle.read(10)) xDPI = _convertToDPI(xDensity, xUnit) yDPI = _convertToDPI(yDensity, yUnit) break boxSize, = struct.unpack('>L', boxHeader[:4]) fhandle.seek(boxSize - 8, 1) headerSize -= boxSize except struct.error as e: raise ValueError("Invalid JPEG2000 file") return xDPI, yDPI
Close