diff --git a/0002-Support-SVG-Image.patch b/0002-Support-SVG-Image.patch new file mode 100644 index 0000000..81cdee5 --- /dev/null +++ b/0002-Support-SVG-Image.patch @@ -0,0 +1,113 @@ +From f921628c24a195ce310e3cf08498273300ec3d6b Mon Sep 17 00:00:00 2001 +From: Takeshi KOMIYA +Date: Sat, 14 Dec 2019 14:28:52 +0900 +Subject: [PATCH] Support SVG Image + +--- + README.rst | 2 +- + imagesize.py | 35 +++++++++++++++++++++++++++++++++++ + test/images/test.svg | 4 ++++ + test/test_get.py | 5 +++++ + 4 files changed, 45 insertions(+), 1 deletion(-) + create mode 100644 test/images/test.svg + +diff --git a/README.rst b/README.rst +index 3bd5b54..1545bf3 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 image headers and returns image size. ++This module analyzes JPEG/JPEG 2000/PNG/GIF/TIFF/SVG image headers and returns image size. + + .. code:: python + +diff --git a/imagesize.py b/imagesize.py +index 2717240..1c3b82d 100644 +--- a/imagesize.py ++++ b/imagesize.py +@@ -1,4 +1,6 @@ ++import re + import struct ++from xml.etree import ElementTree + + _UNIT_KM = -3 + _UNIT_100M = -2 +@@ -52,6 +54,30 @@ def _convertToDPI(density, unit): + return density + + ++def _convertToPx(value): ++ matched = re.match(r"(\d+)(?:\.\d)?([a-z]*)$", value) ++ if not matched: ++ raise ValueError("unknown length value: %s" % value) ++ else: ++ length, unit = matched.groups() ++ if unit == "": ++ return int(length) ++ elif unit == "cm": ++ return int(length) * 96 / 2.54 ++ elif unit == "mm": ++ return int(length) * 96 / 2.54 / 10 ++ elif unit == "in": ++ return int(length) * 96 ++ elif unit == "pc": ++ return int(length) * 96 / 6 ++ elif unit == "pt": ++ return int(length) * 96 / 6 ++ elif unit == "px": ++ return int(length) ++ else: ++ raise ValueError("unknown unit type: %s" % unit) ++ ++ + def get(filepath): + """ + Return (width, height) for a given img file content +@@ -147,6 +173,15 @@ def get(filepath): + break + if width == -1 or height == -1: + raise ValueError("Invalid TIFF file: width and/or height IDS entries are missing.") ++ # handle SVGs ++ elif size >= 5 and head.startswith(b' ++ ++ ++ +diff --git a/test/test_get.py b/test/test_get.py +index c24cd49..70a6309 100644 +--- a/test/test_get.py ++++ b/test/test_get.py +@@ -33,6 +33,11 @@ class GetTest(unittest.TestCase): + self.assertEqual(width, 802) + self.assertEqual(height, 670) + ++ def test_load_svg(self): ++ width, height = imagesize.get(os.path.join(imagedir, "test.svg")) ++ self.assertEqual(width, 90) ++ self.assertEqual(height, 60) ++ + def test_littleendien_tiff(self): + width, height = imagesize.get(os.path.join(imagedir, "multipage_tiff_example.tif")) + self.assertEqual(width, 800) +-- +2.39.0.windows.2 + diff --git a/python-imagesize.spec b/python-imagesize.spec index f8aa62b..6f30720 100644 --- a/python-imagesize.spec +++ b/python-imagesize.spec @@ -1,11 +1,12 @@ Name: python-imagesize Version: 1.1.0 -Release: 2 +Release: 3 Summary: This module analyzes image headers and returns image size. License: MIT URL: https://github.com/shibukawa/imagesize_py Source0: https://files.pythonhosted.org/packages/source/i/imagesize/imagesize-%{version}.tar.gz Patch01: 0001-Added-return-types-to-docstrings-and-fixed-descripti.patch +Patch02: 0002-Support-SVG-Image.patch BuildArch: noarch BuildRequires: python2-setuptools python2-devel python2-pytest python3-setuptools BuildRequires: python3-devel python3-pytest @@ -49,6 +50,8 @@ py.test-3 %{python3_sitelib}/* %changelog +* Thu Nov 09 2023 zhangliangpengkun - 1.1.0-3 +- Support SVG Image * Thu Oct 19 2023 zhangliangpengkun - 1.1.0-2 - Added return types to docstrings, and fixed description of getDPI()'s…