is-page-empty 1.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- is_page_empty-1.0.4/.github/workflows/release.yml +22 -0
- is_page_empty-1.0.4/.gitignore +218 -0
- is_page_empty-1.0.4/LICENSE +21 -0
- is_page_empty-1.0.4/PKG-INFO +45 -0
- is_page_empty-1.0.4/README.md +23 -0
- is_page_empty-1.0.4/pyproject.toml +33 -0
- is_page_empty-1.0.4/src/is_page_empty/__init__.py +62 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build-and-publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: pypi
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write # required for trusted publishing
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v7
|
|
17
|
+
- uses: actions/setup-python@v7
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
- run: pip install build
|
|
21
|
+
- run: python -m build
|
|
22
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 johannes-bauer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: is-page-empty
|
|
3
|
+
Version: 1.0.4
|
|
4
|
+
Summary: A very simple script that tests whether an image is likely empty.
|
|
5
|
+
Project-URL: Homepage, https://github.com/johannes-bauer/is_page_empty
|
|
6
|
+
Author-email: Johannes Bauer <atomm-clap@interesting-problems.de>
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: argument-parser,cli,subcommands
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Provides-Extra: imageio
|
|
15
|
+
Requires-Dist: imageio>=2.0.0; extra == 'imageio'
|
|
16
|
+
Provides-Extra: pil
|
|
17
|
+
Requires-Dist: numpy>=2.2; extra == 'pil'
|
|
18
|
+
Requires-Dist: pillow>=12.0.0; extra == 'pil'
|
|
19
|
+
Provides-Extra: skimage
|
|
20
|
+
Requires-Dist: scikit-image>=0.20.0; extra == 'skimage'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# is_page_empty
|
|
24
|
+
|
|
25
|
+
A simple package/script that checks whether a given image file is empty.
|
|
26
|
+
|
|
27
|
+
Install it with one of the optional dependencies `skimage`, `imageio`, or `pil` or provide that skimage, imageio, or pillow are installed.
|
|
28
|
+
|
|
29
|
+
Then you can check whether an image file is empty using the commandline:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
if is_page_empty some_image.png; then echo "Yes, it's empty"; else echo "No, it's not empty."; fi
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or you can use the package to check programmatically
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import is_page_empty
|
|
39
|
+
if is_empty('path/to/image/file.png'):
|
|
40
|
+
print("That file is empty.")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The script simply cuts the page into small squares, counts the number of pixels below a certain threshold in each, and compares the sum of those numbers in the squares with the highest numbers to a cutoff threshold.
|
|
44
|
+
|
|
45
|
+
This has been very robust, in my experience, for scanned text; in particular in double-sided prints, where some of the print on the other side may shine through, and in pages with punched holes, which are rendered black in the print.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# is_page_empty
|
|
2
|
+
|
|
3
|
+
A simple package/script that checks whether a given image file is empty.
|
|
4
|
+
|
|
5
|
+
Install it with one of the optional dependencies `skimage`, `imageio`, or `pil` or provide that skimage, imageio, or pillow are installed.
|
|
6
|
+
|
|
7
|
+
Then you can check whether an image file is empty using the commandline:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
if is_page_empty some_image.png; then echo "Yes, it's empty"; else echo "No, it's not empty."; fi
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or you can use the package to check programmatically
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import is_page_empty
|
|
17
|
+
if is_empty('path/to/image/file.png'):
|
|
18
|
+
print("That file is empty.")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The script simply cuts the page into small squares, counts the number of pixels below a certain threshold in each, and compares the sum of those numbers in the squares with the highest numbers to a cutoff threshold.
|
|
22
|
+
|
|
23
|
+
This has been very robust, in my experience, for scanned text; in particular in double-sided prints, where some of the print on the other side may shine through, and in pages with punched holes, which are rendered black in the print.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[tool.hatch.build.targets.wheel]
|
|
6
|
+
packages = ["src/is_page_empty"]
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "is-page-empty"
|
|
10
|
+
version = "1.0.4"
|
|
11
|
+
description = "A very simple script that tests whether an image is likely empty."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
license = {text = "MIT"}
|
|
15
|
+
dependencies = []
|
|
16
|
+
authors = [{name = "Johannes Bauer", email = "atomm-clap@interesting-problems.de"}]
|
|
17
|
+
keywords = ["cli", "argument-parser", "subcommands"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Topic :: Software Development :: Libraries",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/johannes-bauer/is_page_empty"
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
skimage = ["scikit-image>=0.20.0"]
|
|
29
|
+
imageio = ["ImageIO>=2.0.0"]
|
|
30
|
+
pil = ["pillow>=12.0.0", "numpy>=2.2"]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
is_page_empty = "is_page_empty:main"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import skimage
|
|
3
|
+
def load_image(fn):
|
|
4
|
+
return skimage.io.imread(fn)
|
|
5
|
+
except ImportError:
|
|
6
|
+
try:
|
|
7
|
+
import imageio.v3 as iio
|
|
8
|
+
def load_image(fn):
|
|
9
|
+
return iio.imread(fn)
|
|
10
|
+
except ImportError:
|
|
11
|
+
import PIL, numpy
|
|
12
|
+
def load_image(fn):
|
|
13
|
+
im = PIL.Image.open(fn)
|
|
14
|
+
return numpy.array(im)
|
|
15
|
+
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
CUTOFF = 0.02
|
|
19
|
+
|
|
20
|
+
def score(im):
|
|
21
|
+
ratio_bright = (im > 127).mean()
|
|
22
|
+
return min(ratio_bright, 1-ratio_bright)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def is_empty(im, cutoff=CUTOFF):
|
|
26
|
+
if isinstance(im, str):
|
|
27
|
+
im = load_image(im)
|
|
28
|
+
if len(im.shape) == 3:
|
|
29
|
+
im = im[..., 0] / 3 + im[..., 1] / 3 + im[..., 2] / 3
|
|
30
|
+
|
|
31
|
+
smaller_dim, larger_dim = sorted(im.shape)
|
|
32
|
+
max_stride = smaller_dim / 10
|
|
33
|
+
|
|
34
|
+
scores = [
|
|
35
|
+
score(im[
|
|
36
|
+
x:int(x+max_stride),
|
|
37
|
+
y:int(y+max_stride)
|
|
38
|
+
])
|
|
39
|
+
for x in range(0, (im.shape[0] - int(max_stride) - 1), int(max_stride))
|
|
40
|
+
for y in range(0, (im.shape[1] - int(max_stride) - 1), int(max_stride))
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
im_score = sum(sorted(scores)[-3:]) / 3
|
|
44
|
+
return im_score < cutoff, im_score
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main():
|
|
48
|
+
import argparse
|
|
49
|
+
parser = argparse.ArgumentParser()
|
|
50
|
+
parser.add_argument('infile')
|
|
51
|
+
parser.add_argument('-c', dest='cutoff', type=float, default=CUTOFF)
|
|
52
|
+
parser.add_argument('-r', dest='retval', action='store_true')
|
|
53
|
+
parser.add_argument('-v', dest='verbose', action='store_true')
|
|
54
|
+
args = parser.parse_args()
|
|
55
|
+
empty, im_score = is_empty(args.infile, args.cutoff)
|
|
56
|
+
if args.verbose:
|
|
57
|
+
verdict = '' if empty else 'not '
|
|
58
|
+
print(f"File {args.infile} is {verdict}empty (score: {im_score})")
|
|
59
|
+
if args.retval:
|
|
60
|
+
status=(0 if empty else 1)
|
|
61
|
+
sys.exit(status)
|
|
62
|
+
|