Compare commits

..

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
da550e1d61
!46 Fix Python 3.7 Travis testing
From: @zhang-liang-pengkun 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-12-29 08:46:49 +00:00
zhang-liang-pengkun
e39e738cc0 Fix Python 3.7 Travis testing
Signed-off-by: zhang-liang-pengkun <zhangliangpengkun@xfusion.com>
2023-12-29 16:25:03 +08:00
openeuler-ci-bot
daaa6dbb36
!40 Make sure *.pyc files are not included in the tarball
From: @zhang-liang-pengkun 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-12-28 09:43:15 +00:00
zhang-liang-pengkun
f54f41c001 Make sure *.pyc files are not included in the tarball
Signed-off-by: zhang-liang-pengkun <zhangliangpengkun@xfusion.com>
2023-12-28 15:07:00 +08:00
openeuler-ci-bot
fe2c6f1467
!33 Pass python_requires argument to setuptools
From: @zhang-liang-pengkun 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-12-25 08:40:25 +00:00
zhang-liang-pengkun
5c4b8c5612 Pass python_requires argument to setuptools
Signed-off-by: zhang-liang-pengkun <zhangliangpengkun@xfusion.com>
2023-12-21 18:09:14 +08:00
openeuler-ci-bot
afca6fe6d1
!29 Support SVG Image
From: @zhang-liang-pengkun 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-11-10 03:18:17 +00:00
zhang-liang-pengkun
0c0d2e0028 Support SVG Image
Signed-off-by: zhang-liang-pengkun <zhangliangpengkun@xfusion.com>
2023-11-10 09:56:23 +08:00
openeuler-ci-bot
e450ee05ef
!20 Added return types to docstrings, and fixed description of getDPI()'s…
From: @zhang-liang-pengkun 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-10-19 09:53:30 +00:00
zhang-liang-pengkun
248c5e3d45 Added return types to docstrings, and fixed description of getDPI()'s¡­
Signed-off-by: zhang-liang-pengkun <zhangliangpengkun@xfusion.com>
2023-10-19 14:48:29 +08:00
6 changed files with 268 additions and 2 deletions

View File

@ -0,0 +1,36 @@
From 2f73f20f73cfe097d6838b45eee22cb300d9cc04 Mon Sep 17 00:00:00 2001
From: Tyler Young <tyler@x-plane.com>
Date: Tue, 27 Aug 2019 12:43:35 -0500
Subject: [PATCH] Added return types to docstrings, and fixed description of
getDPI()'s return
---
imagesize.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/imagesize.py b/imagesize.py
index 2717240..b0fbfb2 100644
--- a/imagesize.py
+++ b/imagesize.py
@@ -56,6 +56,7 @@ def get(filepath):
"""
Return (width, height) for a given img file content
no requirements
+ :rtype Tuple[int, int]
"""
height = -1
width = -1
@@ -153,8 +154,9 @@ def get(filepath):
def getDPI(filepath):
"""
- Return (width, height) for a given img file content
+ Return (x DPI, y DPI) for a given img file content
no requirements
+ :rtype Tuple[int, int]
"""
xDPI = -1
yDPI = -1
--
2.39.0.windows.2

View File

@ -0,0 +1,113 @@
From f921628c24a195ce310e3cf08498273300ec3d6b Mon Sep 17 00:00:00 2001
From: Takeshi KOMIYA <i.tkomiya@gmail.com>
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'<?xml'):
+ try:
+ fhandle.seek(0)
+ root = ElementTree.parse(fhandle).getroot()
+ width = _convertToPx(root.attrib["width"])
+ height = _convertToPx(root.attrib["height"])
+ except Exception:
+ raise ValueError("Invalid SVG file")
return width, height
diff --git a/test/images/test.svg b/test/images/test.svg
new file mode 100644
index 0000000..28d4b39
--- /dev/null
+++ b/test/images/test.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="60" width="90">
+ <circle cx="40" cy="40" r="24" style="stroke:#000000; fill:#ffffff"/>
+</svg>
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

View File

@ -0,0 +1,40 @@
From a1dab8487f8fdfdab4429dbe8ff1683907f08c48 Mon Sep 17 00:00:00 2001
From: Jon Dufresne <jon.dufresne@gmail.com>
Date: Thu, 12 Apr 2018 04:15:49 -0700
Subject: [PATCH] Pass python_requires argument to setuptools
Helps pip decide what version of the library to install.
https://packaging.python.org/tutorials/distributing-packages/#python-requires
> If your project only runs on certain Python versions, setting the
> python_requires argument to the appropriate PEP 440 version specifier
> string will prevent pip from installing the project on other Python
> versions.
https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords
> python_requires
>
> A string corresponding to a version specifier (as defined in PEP 440)
> for the Python version, used to specify the Requires-Python defined in
> PEP 345.
---
setup.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/setup.py b/setup.py
index bf3f7c3..06f2946 100644
--- a/setup.py
+++ b/setup.py
@@ -21,6 +21,7 @@ This is a pure Python library.
license="MIT",
py_modules=['imagesize'],
test_suite='test',
+ python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
--
2.39.0.windows.2

View File

@ -0,0 +1,21 @@
From a47f231502a5522578e8399f068c05a99399f4b1 Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev <mitya57@gmail.com>
Date: Tue, 4 Sep 2018 13:10:53 +0300
Subject: [PATCH] Make sure *.pyc files are not included in the tarball
---
MANIFEST.in | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/MANIFEST.in b/MANIFEST.in
index afe1754..3b6b34c 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,2 +1,3 @@
include LICENSE.rst
-graft test
+include test/*.py
+include test/images/*
--
2.39.0.windows.2

View File

@ -0,0 +1,36 @@
From 4b14779126b0a3fccd1f4843067dd472bdc421f4 Mon Sep 17 00:00:00 2001
From: Jon Dufresne <jon.dufresne@gmail.com>
Date: Sat, 15 Sep 2018 09:49:47 -0700
Subject: [PATCH] Fix Python 3.7 Travis testing
Use 'dist: xenial' in Travis to simplify configuration. Allows using
Python version 3.7 without sudo declarations. Travis officially added
support for Xenial on 2018-11-08.
https://blog.travis-ci.com/2018-11-08-xenial-release
---
.travis.yml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 63e8545..3da2af8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,4 @@
+dist: xenial
language: python
cache: pip
python:
@@ -6,7 +7,8 @@ python:
- "3.5"
- "3.6"
- "3.7"
- - "pypy"
+ - "pypy2.7-6.0"
+ - "pypy3.5-6.0"
install:
- pip install nose
script: nosetests
--
2.39.0.windows.2

View File

@ -1,10 +1,15 @@
Name: python-imagesize
Version: 1.1.0
Release: 1
Release: 6
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
Patch03: 0003-Pass-python_requires-argument-to-setuptools.patch
Patch04: 0004-Make-sure-.pyc-files-are-not-included-in-the-tarball.patch
Patch05: 0005-Fix-Python-3.7-Travis-testing.patch
BuildArch: noarch
BuildRequires: python2-setuptools python2-devel python2-pytest python3-setuptools
BuildRequires: python3-devel python3-pytest
@ -27,7 +32,7 @@ Summary: This module analyzes image headers and returns image size.
This module analyzes JPEG/JPEG 2000/PNG/GIF/TIFF image headers and returns image size.
%prep
%autosetup -n imagesize-%{version}
%autosetup -n imagesize-%{version} -p1
rm -rf imagesize.egg-info
%build
%py2_build
@ -48,6 +53,21 @@ py.test-3
%{python3_sitelib}/*
%changelog
* Fri Dec 29 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> - 1.1.0-6
- Fix Python 3.7 Travis testing
* Thu Dec 28 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> - 1.1.0-5
- Make sure *.pyc files are not included in the tarball
* Thu Oct 23 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> - 1.1.0-4
- Pass python_requires argument to setuptools
* Thu Nov 09 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> - 1.1.0-3
- Support SVG Image
* Thu Oct 19 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> - 1.1.0-2
- Added return types to docstrings, and fixed description of getDPI()'s…
* Tue Aug 04 2020 Yeqing Peng <pengyeqing@huawei.com> - 1.1.0-1
- update to 1.1.0