fotolab 0.25.1__tar.gz → 0.26.0__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.
Files changed (43) hide show
  1. {fotolab-0.25.1 → fotolab-0.26.0}/CHANGELOG.md +5 -0
  2. {fotolab-0.25.1 → fotolab-0.26.0}/PKG-INFO +1 -1
  3. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/__init__.py +12 -10
  4. fotolab-0.26.0/fotolab/subcommands/halftone.py +93 -0
  5. {fotolab-0.25.1 → fotolab-0.26.0}/.coveragerc +0 -0
  6. {fotolab-0.25.1 → fotolab-0.26.0}/.gitignore +0 -0
  7. {fotolab-0.25.1 → fotolab-0.26.0}/.pre-commit-config.yaml +0 -0
  8. {fotolab-0.25.1 → fotolab-0.26.0}/.python-version +0 -0
  9. {fotolab-0.25.1 → fotolab-0.26.0}/CONTRIBUTING.md +0 -0
  10. {fotolab-0.25.1 → fotolab-0.26.0}/LICENSE.md +0 -0
  11. {fotolab-0.25.1 → fotolab-0.26.0}/Pipfile +0 -0
  12. {fotolab-0.25.1 → fotolab-0.26.0}/Pipfile.lock +0 -0
  13. {fotolab-0.25.1 → fotolab-0.26.0}/README.md +0 -0
  14. {fotolab-0.25.1 → fotolab-0.26.0}/docs/Makefile +0 -0
  15. {fotolab-0.25.1 → fotolab-0.26.0}/docs/make.bat +0 -0
  16. {fotolab-0.25.1 → fotolab-0.26.0}/docs/source/CHANGELOG.md +0 -0
  17. {fotolab-0.25.1 → fotolab-0.26.0}/docs/source/CONTRIBUTING.md +0 -0
  18. {fotolab-0.25.1 → fotolab-0.26.0}/docs/source/LICENSE.md +0 -0
  19. {fotolab-0.25.1 → fotolab-0.26.0}/docs/source/README.md +0 -0
  20. {fotolab-0.25.1 → fotolab-0.26.0}/docs/source/_static/logo.jpg +0 -0
  21. {fotolab-0.25.1 → fotolab-0.26.0}/docs/source/conf.py +0 -0
  22. {fotolab-0.25.1 → fotolab-0.26.0}/docs/source/index.rst +0 -0
  23. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/__main__.py +0 -0
  24. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/cli.py +0 -0
  25. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/__init__.py +0 -0
  26. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/animate.py +0 -0
  27. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/auto.py +0 -0
  28. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/border.py +0 -0
  29. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/contrast.py +0 -0
  30. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/env.py +0 -0
  31. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/info.py +0 -0
  32. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/montage.py +0 -0
  33. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/resize.py +0 -0
  34. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/rotate.py +0 -0
  35. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/sharpen.py +0 -0
  36. {fotolab-0.25.1 → fotolab-0.26.0}/fotolab/subcommands/watermark.py +0 -0
  37. {fotolab-0.25.1 → fotolab-0.26.0}/noxfile.py +0 -0
  38. {fotolab-0.25.1 → fotolab-0.26.0}/pyproject.toml +0 -0
  39. {fotolab-0.25.1 → fotolab-0.26.0}/tests/__init__.py +0 -0
  40. {fotolab-0.25.1 → fotolab-0.26.0}/tests/conftest.py +0 -0
  41. {fotolab-0.25.1 → fotolab-0.26.0}/tests/test_env.py +0 -0
  42. {fotolab-0.25.1 → fotolab-0.26.0}/tests/test_help_flag.py +0 -0
  43. {fotolab-0.25.1 → fotolab-0.26.0}/tests/test_quiet_flag.py +0 -0
@@ -7,6 +7,11 @@ and this project adheres to [0-based versioning](https://0ver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## v0.26.0 (2025-01-19)
11
+
12
+ - Add `halftone` subcommand
13
+ - Refactor open image using default program
14
+
10
15
  ## v0.25.1 (2025-01-13)
11
16
 
12
17
  - Bump deps
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fotolab
3
- Version: 0.25.1
3
+ Version: 0.26.0
4
4
  Summary: A console program that manipulate images.
5
5
  Keywords: photography,photo
6
6
  Author-email: Kian-Meng Ang <kianmeng@cpan.org>
@@ -16,12 +16,11 @@
16
16
  """A console program that manipulate images."""
17
17
 
18
18
  import logging
19
- import os
20
19
  import subprocess
21
20
  import sys
22
21
  from pathlib import Path
23
22
 
24
- __version__ = "0.25.1"
23
+ __version__ = "0.26.0"
25
24
 
26
25
  log = logging.getLogger(__name__)
27
26
 
@@ -57,11 +56,14 @@ def save_image(args, new_image, output_filename, subcommand):
57
56
 
58
57
  def _open_image(filename):
59
58
  """Open generated image using default program."""
60
- if sys.platform == "linux":
61
- subprocess.call(["xdg-open", filename])
62
- elif sys.platform == "darwin":
63
- subprocess.call(["open", filename])
64
- elif sys.platform == "windows":
65
- os.startfile(filename)
66
-
67
- log.info("open image: %s", filename.resolve())
59
+ platform_open_func = {
60
+ "linux": subprocess.call(["xdg-open", filename]),
61
+ "darwin": subprocess.call(["open", filename]),
62
+ "windows": subprocess.Popen(["start", filename]),
63
+ }
64
+ try:
65
+ platform_open_func[sys.platform]
66
+ except KeyError:
67
+ print(f"Unsupported platform: {sys.platform}")
68
+ else:
69
+ log.info("open image: %s", filename.resolve())
@@ -0,0 +1,93 @@
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify it under
4
+ # the terms of the GNU Affero General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
+ # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU Affero General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ """Halftone subcommand."""
17
+
18
+ import argparse
19
+ import logging
20
+ import math
21
+
22
+ from PIL import Image, ImageDraw
23
+
24
+ from fotolab import save_image
25
+
26
+ log = logging.getLogger(__name__)
27
+
28
+
29
+ def build_subparser(subparsers) -> None:
30
+ """Build the subparser."""
31
+ halftone_parser = subparsers.add_parser(
32
+ "halftone", help="halftone an image"
33
+ )
34
+
35
+ halftone_parser.set_defaults(func=run)
36
+
37
+ halftone_parser.add_argument(
38
+ dest="image_filenames",
39
+ help="set the image filename",
40
+ nargs="+",
41
+ type=str,
42
+ default=None,
43
+ metavar="IMAGE_FILENAMES",
44
+ )
45
+
46
+
47
+ def run(args: argparse.Namespace) -> None:
48
+ """Run halftone subcommand.
49
+
50
+ Args:
51
+ config (argparse.Namespace): Config from command line arguments
52
+
53
+ Returns:
54
+ None
55
+ """
56
+ log.debug(args)
57
+
58
+ for image_filename in args.image_filenames:
59
+ original_image = Image.open(image_filename)
60
+ grayscale_image = original_image.convert("L")
61
+ width, height = original_image.size
62
+
63
+ halftone_image = Image.new("L", (width, height), "black")
64
+ draw = ImageDraw.Draw(halftone_image)
65
+
66
+ # modified from the circular halftone effect processing.py example from
67
+ # https://tabreturn.github.io/code/processing/python/2019/02/09/processing.py_in_ten_lessons-6.3-_halftones.html
68
+ coltotal = 50
69
+ cellsize = width / coltotal
70
+ rowtotal = math.ceil(height / cellsize)
71
+
72
+ col = 0
73
+ row = 0
74
+
75
+ for _ in range(int(coltotal * rowtotal)):
76
+ x = int(col * cellsize)
77
+ y = int(row * cellsize)
78
+ col += 1
79
+
80
+ if col >= coltotal:
81
+ col = 0
82
+ row += 1
83
+
84
+ x = int(x + cellsize / 2)
85
+ y = int(y + cellsize / 2)
86
+
87
+ brightness = grayscale_image.getpixel((x, y))
88
+ amp = 10 * brightness / 200
89
+ draw.ellipse(
90
+ [x - amp / 2, y - amp / 2, x + amp / 2, y + amp / 2], fill=255
91
+ )
92
+
93
+ save_image(args, halftone_image, image_filename, "halftone")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes