diff --git a/PKG-INFO b/PKG-INFO index ca67e11a9f90d274049761882e8d2b266682c1f6..8f8648fce8d8a3851387969820ac155b4aec2f3f 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: imagesize -Version: 1.3.0 +Version: 1.4.1 Summary: Getting image size from png/jpeg/jpeg2000/gif file Home-page: https://github.com/shibukawa/imagesize_py Author: Yoshiki Shibukawa @@ -22,6 +22,7 @@ Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Multimedia :: Graphics @@ -38,6 +39,7 @@ It parses image files' header and return image size. * TIFF * SVG * Netpbm +* WebP This is a pure Python library. diff --git a/README.rst b/README.rst index d1441b70433ad75c8b363a7779a0568747bee7e7..9704d22bfa53261cd6304aca589c67620b04877c 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ imagesize .. image:: https://travis-ci.org/shibukawa/imagesize_py.svg?branch=master :target: https://travis-ci.org/shibukawa/imagesize_py -This module analyzes JPEG/JPEG 2000/PNG/GIF/TIFF/SVG/Netpbm image headers and returns image size or DIP. +This module analyzes JPEG/JPEG 2000/PNG/GIF/TIFF/SVG/Netpbm/WebP image headers and returns image size or DIP. .. code:: python @@ -90,3 +90,4 @@ Thank you for feedback: * Hannes Römer (https://github.com/hroemer) * mikey (https://github.com/ffreemt) * Marco (https://github.com/marcoffee) +* ExtReMLapin (https://github.com/ExtReMLapin) diff --git a/imagesize.egg-info/PKG-INFO b/imagesize.egg-info/PKG-INFO index ca67e11a9f90d274049761882e8d2b266682c1f6..8f8648fce8d8a3851387969820ac155b4aec2f3f 100644 --- a/imagesize.egg-info/PKG-INFO +++ b/imagesize.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: imagesize -Version: 1.3.0 +Version: 1.4.1 Summary: Getting image size from png/jpeg/jpeg2000/gif file Home-page: https://github.com/shibukawa/imagesize_py Author: Yoshiki Shibukawa @@ -22,6 +22,7 @@ Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Multimedia :: Graphics @@ -38,6 +39,7 @@ It parses image files' header and return image size. * TIFF * SVG * Netpbm +* WebP This is a pure Python library. diff --git a/imagesize.egg-info/SOURCES.txt b/imagesize.egg-info/SOURCES.txt index 6a2b93377108f6c052ead61580c290398296bc57..3c036d7eb46b75fa7e261d9feb26b88eb7d259ad 100644 --- a/imagesize.egg-info/SOURCES.txt +++ b/imagesize.egg-info/SOURCES.txt @@ -1,9 +1,10 @@ LICENSE.rst MANIFEST.in README.rst -imagesize.py setup.cfg setup.py +imagesize/__init__.py +imagesize/imagesize.py imagesize.egg-info/PKG-INFO imagesize.egg-info/SOURCES.txt imagesize.egg-info/dependency_links.txt diff --git a/imagesize/__init__.py b/imagesize/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8f001b645c0590740e6674ba8ea2bedda7ea452d --- /dev/null +++ b/imagesize/__init__.py @@ -0,0 +1,5 @@ +__all__ = ["get", "getDPI", "__version__"] + +__version__ = "1.4.1" + +from .imagesize import get, getDPI diff --git a/imagesize.py b/imagesize/imagesize.py similarity index 95% rename from imagesize.py rename to imagesize/imagesize.py index f700f14379bb536b6a19366d6ecc906744bae9ed..e6ed07eaeb90c00b7ef50636d26c92dc2d652a7f 100644 --- a/imagesize.py +++ b/imagesize/imagesize.py @@ -96,7 +96,7 @@ def get(filepath): fhandle = open(filepath, 'rb') try: - head = fhandle.read(24) + head = fhandle.read(31) size = len(head) # handle GIFs if size >= 10 and head[:6] in (b'GIF87a', b'GIF89a'): @@ -249,6 +249,18 @@ def get(filepath): fhandle.seek(-1, os.SEEK_CUR) width, height = sizes + elif head.startswith(b"RIFF") and head[8:12] == b"WEBP": + if head[12:16] == b"VP8 ": + width, height = struct.unpack("<HH", head[26:30]) + elif head[12:16] == b"VP8X": + width = struct.unpack("<I", head[24:27] + b"\0")[0] + height = struct.unpack("<I", head[27:30] + b"\0")[0] + elif head[12:16] == b"VP8L": + b = head[21:25] + width = (((b[1] & 63) << 8) | b[0]) + 1 + height = (((b[3] & 15) << 10) | (b[2] << 2) | ((b[1] & 192) >> 6)) + 1 + else: + raise ValueError("Unsupported WebP file") finally: fhandle.close() diff --git a/setup.py b/setup.py index bf3ebd24185edab18f723e3ee9b980000c867887..00db6077d4b732635b726da9a614413b15e7b9eb 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,10 @@ #!/usr/bin/env python from setuptools import setup +from imagesize import __version__ setup(name='imagesize', - version='1.3.0', + version=__version__, description='Getting image size from png/jpeg/jpeg2000/gif file', long_description=''' It parses image files' header and return image size. @@ -15,6 +16,7 @@ It parses image files' header and return image size. * TIFF * SVG * Netpbm +* WebP This is a pure Python library. ''', @@ -22,7 +24,7 @@ This is a pure Python library. author_email='yoshiki@shibu.jp', url='https://github.com/shibukawa/imagesize_py', license="MIT", - py_modules=['imagesize'], + packages=['imagesize'], python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", classifiers=[ @@ -41,6 +43,7 @@ This is a pure Python library. 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Multimedia :: Graphics'