Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-imagesize for
openSUSE:Factory checked in at 2022-07-26 19:42:03
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-imagesize (Old)
and /work/SRC/openSUSE:Factory/.python-imagesize.new.1533 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-imagesize"
Tue Jul 26 19:42:03 2022 rev:9 rq:990796 version:1.4.1
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-imagesize/python-imagesize.changes
2022-01-11 21:20:38.077016433 +0100
+++
/work/SRC/openSUSE:Factory/.python-imagesize.new.1533/python-imagesize.changes
2022-07-26 19:42:04.521584287 +0200
@@ -1,0 +2,7 @@
+Sat Jul 23 11:27:23 UTC 2022 - Dirk M??ller <[email protected]>
+
+- update to 1.4.1:
+ * python 3.10 compat
+ * documentation updates
+
+-------------------------------------------------------------------
Old:
----
imagesize-1.3.0.tar.gz
New:
----
imagesize-1.4.1.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-imagesize.spec ++++++
--- /var/tmp/diff_new_pack.RhkeBf/_old 2022-07-26 19:42:04.949518160 +0200
+++ /var/tmp/diff_new_pack.RhkeBf/_new 2022-07-26 19:42:04.953517542 +0200
@@ -18,7 +18,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name: python-imagesize
-Version: 1.3.0
+Version: 1.4.1
Release: 0
Summary: Getting image size from PNG/JPEG/JPEG2000/GIF files
License: MIT
@@ -30,7 +30,6 @@
# SECTION test requirements
BuildRequires: %{python_module pytest}
# /SECTION
-BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
%python_subpackages
@@ -58,7 +57,6 @@
%pytest
%files %{python_files}
-%defattr(-,root,root,-)
%{python_sitelib}/*
%doc README.rst
++++++ imagesize-1.3.0.tar.gz -> imagesize-1.4.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/imagesize-1.3.0/PKG-INFO new/imagesize-1.4.1/PKG-INFO
--- old/imagesize-1.3.0/PKG-INFO 2021-11-09 17:05:46.005883700 +0100
+++ new/imagesize-1.4.1/PKG-INFO 2022-07-01 14:19:48.747215700 +0200
@@ -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.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 @@
* TIFF
* SVG
* Netpbm
+* WebP
This is a pure Python library.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/imagesize-1.3.0/README.rst
new/imagesize-1.4.1/README.rst
--- old/imagesize-1.3.0/README.rst 2021-11-09 16:28:59.000000000 +0100
+++ new/imagesize-1.4.1/README.rst 2022-07-01 14:06:08.000000000 +0200
@@ -4,7 +4,7 @@
.. 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 @@
* Hannes R??mer (https://github.com/hroemer)
* mikey (https://github.com/ffreemt)
* Marco (https://github.com/marcoffee)
+* ExtReMLapin (https://github.com/ExtReMLapin)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/imagesize-1.3.0/imagesize/__init__.py
new/imagesize-1.4.1/imagesize/__init__.py
--- old/imagesize-1.3.0/imagesize/__init__.py 1970-01-01 01:00:00.000000000
+0100
+++ new/imagesize-1.4.1/imagesize/__init__.py 2022-07-01 14:15:35.000000000
+0200
@@ -0,0 +1,5 @@
+__all__ = ["get", "getDPI", "__version__"]
+
+__version__ = "1.4.1"
+
+from .imagesize import get, getDPI
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/imagesize-1.3.0/imagesize/imagesize.py
new/imagesize-1.4.1/imagesize/imagesize.py
--- old/imagesize-1.3.0/imagesize/imagesize.py 1970-01-01 01:00:00.000000000
+0100
+++ new/imagesize-1.4.1/imagesize/imagesize.py 2022-07-01 14:14:01.000000000
+0200
@@ -0,0 +1,376 @@
+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(31)
+ 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
+ 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()
+
+ 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
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/imagesize-1.3.0/imagesize.egg-info/PKG-INFO
new/imagesize-1.4.1/imagesize.egg-info/PKG-INFO
--- old/imagesize-1.3.0/imagesize.egg-info/PKG-INFO 2021-11-09
17:05:45.000000000 +0100
+++ new/imagesize-1.4.1/imagesize.egg-info/PKG-INFO 2022-07-01
14:19:48.000000000 +0200
@@ -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.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 @@
* TIFF
* SVG
* Netpbm
+* WebP
This is a pure Python library.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/imagesize-1.3.0/imagesize.egg-info/SOURCES.txt
new/imagesize-1.4.1/imagesize.egg-info/SOURCES.txt
--- old/imagesize-1.3.0/imagesize.egg-info/SOURCES.txt 2021-11-09
17:05:45.000000000 +0100
+++ new/imagesize-1.4.1/imagesize.egg-info/SOURCES.txt 2022-07-01
14:19:48.000000000 +0200
@@ -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 -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/imagesize-1.3.0/imagesize.py
new/imagesize-1.4.1/imagesize.py
--- old/imagesize-1.3.0/imagesize.py 2021-11-09 16:08:05.000000000 +0100
+++ new/imagesize-1.4.1/imagesize.py 1970-01-01 01:00:00.000000000 +0100
@@ -1,364 +0,0 @@
-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
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/imagesize-1.3.0/setup.py new/imagesize-1.4.1/setup.py
--- old/imagesize-1.3.0/setup.py 2021-11-09 16:29:46.000000000 +0100
+++ new/imagesize-1.4.1/setup.py 2022-07-01 14:18:34.000000000 +0200
@@ -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 @@
* TIFF
* SVG
* Netpbm
+* WebP
This is a pure Python library.
''',
@@ -22,7 +24,7 @@
author_email='[email protected]',
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 @@
'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'