fotolab 0.24.0__py3-none-any.whl → 0.26.0__py3-none-any.whl

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.
fotolab/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -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.24.0"
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())
fotolab/cli.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
 
3
3
  # This program is free software: you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -70,6 +70,7 @@ def run(args: argparse.Namespace) -> None:
70
70
  "camera": False,
71
71
  "canvas": False,
72
72
  "lowercase": False,
73
+ "before_after": False,
73
74
  }
74
75
  combined_args = argparse.Namespace(**vars(args), **extra_args)
75
76
  combined_args.overwrite = True
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -115,25 +115,28 @@ def run(args: argparse.Namespace) -> None:
115
115
  for image_filename in args.image_filenames:
116
116
  original_image = Image.open(image_filename)
117
117
 
118
- if (
119
- args.width_left
120
- or args.width_top
121
- or args.width_right
122
- or args.width_bottom
123
- ):
124
- border = (
125
- int(args.width_left),
126
- int(args.width_top),
127
- int(args.width_right),
128
- int(args.width_bottom),
129
- )
130
- else:
131
- border = args.width
132
-
118
+ border = get_border(args)
133
119
  bordered_image = ImageOps.expand(
134
120
  original_image,
135
121
  border=border,
136
122
  fill=ImageColor.getrgb(args.color),
137
123
  )
138
124
 
139
- save_image(args, bordered_image, image_filename, "watermark")
125
+ save_image(args, bordered_image, image_filename, "border")
126
+
127
+
128
+ def get_border(args: argparse.Namespace) -> tuple:
129
+ """Calculate the border."""
130
+ if (
131
+ args.width_left
132
+ or args.width_top
133
+ or args.width_right
134
+ or args.width_bottom
135
+ ):
136
+ return (
137
+ int(args.width_left),
138
+ int(args.width_top),
139
+ int(args.width_right),
140
+ int(args.width_bottom),
141
+ )
142
+ return args.width
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -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")
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -97,7 +97,6 @@ def run(args: argparse.Namespace) -> None:
97
97
 
98
98
  def extract_exif_tags(image: Image.Image, sort: bool = False) -> dict:
99
99
  """Extract Exif metadata from image."""
100
- print(type(image))
101
100
  exif = image._getexif()
102
101
  log.debug(exif)
103
102
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -63,9 +63,9 @@ def run(args: argparse.Namespace) -> None:
63
63
  montaged_image = Image.new("RGB", (total_width, total_height))
64
64
 
65
65
  x_offset = 0
66
- for img in images:
67
- montaged_image.paste(img, (x_offset, 0))
68
- x_offset += img.width
66
+ for image in images:
67
+ montaged_image.paste(image, (x_offset, 0))
68
+ x_offset += image.width
69
69
 
70
70
  output_image_filename = args.image_filenames[0].name
71
71
  save_image(args, montaged_image, output_image_filename, "montage")
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -17,10 +17,11 @@
17
17
 
18
18
  import argparse
19
19
  import logging
20
+ from pathlib import Path
20
21
 
21
22
  from PIL import Image, ImageFilter
22
23
 
23
- from fotolab import save_image
24
+ from fotolab import _open_image, save_image
24
25
 
25
26
  log = logging.getLogger(__name__)
26
27
 
@@ -76,6 +77,15 @@ def build_subparser(subparsers) -> None:
76
77
  metavar="THRESHOLD",
77
78
  )
78
79
 
80
+ sharpen_parser.add_argument(
81
+ "-ba",
82
+ "--before-after",
83
+ default=False,
84
+ action="store_true",
85
+ dest="before_after",
86
+ help="generate a GIF showing before and after changes",
87
+ )
88
+
79
89
 
80
90
  def run(args: argparse.Namespace) -> None:
81
91
  """Run sharpen subcommand.
@@ -95,4 +105,31 @@ def run(args: argparse.Namespace) -> None:
95
105
  args.radius, percent=args.percent, threshold=args.threshold
96
106
  )
97
107
  )
98
- save_image(args, sharpen_image, image_filename, "sharpen")
108
+ if args.before_after:
109
+ save_gif_image(args, image_filename, original_image, sharpen_image)
110
+ else:
111
+ save_image(args, sharpen_image, image_filename, "sharpen")
112
+
113
+
114
+ def save_gif_image(args, image_filename, original_image, sharpen_image):
115
+ """Save the original and sharpen image."""
116
+ image_file = Path(image_filename)
117
+ new_filename = Path(
118
+ args.output_dir,
119
+ image_file.with_name(f"sharpen_gif_{image_file.stem}.gif"),
120
+ )
121
+ new_filename.parent.mkdir(parents=True, exist_ok=True)
122
+
123
+ log.info("sharpen gif image: %s", new_filename)
124
+ original_image.save(
125
+ new_filename,
126
+ format="gif",
127
+ append_images=[sharpen_image],
128
+ save_all=True,
129
+ duration=2500,
130
+ loop=0,
131
+ optimize=True,
132
+ )
133
+
134
+ if args.open:
135
+ _open_image(new_filename)
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2024 Kian-Meng Ang
1
+ # Copyright (C) 2024,2025 Kian-Meng Ang
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify it under
4
4
  # the terms of the GNU Affero General Public License as published by the Free
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fotolab
3
- Version: 0.24.0
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>
@@ -300,7 +300,7 @@ fotolab sharpen -h
300
300
  <!--help-sharpen !-->
301
301
 
302
302
  ```console
303
- usage: fotolab sharpen [-h] [-r RADIUS] [-p PERCENT] [-t THRESHOLD]
303
+ usage: fotolab sharpen [-h] [-r RADIUS] [-p PERCENT] [-t THRESHOLD] [-ba]
304
304
  IMAGE_FILENAMES [IMAGE_FILENAMES ...]
305
305
 
306
306
  positional arguments:
@@ -315,6 +315,7 @@ options:
315
315
  -t, --threshold THRESHOLD
316
316
  set the minimum brightness changed to be sharpened
317
317
  (default: '3')
318
+ -ba, --before-after generate a GIF showing before and after changes
318
319
  ```
319
320
 
320
321
  <!--help-sharpen !-->
@@ -385,7 +386,7 @@ options:
385
386
 
386
387
  ## Copyright and License
387
388
 
388
- Copyright (C) 2024 Kian-Meng Ang
389
+ Copyright (C) 2024,2025 Kian-Meng Ang
389
390
 
390
391
  This program is free software: you can redistribute it and/or modify it under
391
392
  the terms of the GNU Affero General Public License as published by the Free
@@ -0,0 +1,21 @@
1
+ fotolab/__init__.py,sha256=FdS_YCS6GmyfP-phGNKZHFHmHb-2iPRgPDb-VNHm9DI,2173
2
+ fotolab/__main__.py,sha256=aboOURPs_snOXTEWYR0q8oq1UTY9e-NxCd1j33V0wHI,833
3
+ fotolab/cli.py,sha256=9rhS-yhX1nE_zKBfR05QyEt-S7Y43mIP0yUQA6bsgV8,4326
4
+ fotolab/subcommands/__init__.py,sha256=l3DlIaJ3u3jGjnC1H1yV8LZ_nPqOLJ6gikD4BCaMAQ0,1129
5
+ fotolab/subcommands/animate.py,sha256=Zp0LPM7ktg6V2rIAP8pof2mmPAph_0O3TEySvg55-h8,2972
6
+ fotolab/subcommands/auto.py,sha256=p_e1f4mcrIFLqBXMNKvPQRDkNrAlK7FR6sdR5NAR0t8,2427
7
+ fotolab/subcommands/border.py,sha256=v5rdLb7Yq1kQI0MTSfVb0iroBroTV8oxOk-jMLB2who,3637
8
+ fotolab/subcommands/contrast.py,sha256=8uPCd5xI-aUsL7rjdEPmfSskdzMwM-1tv0eRRONkW2M,2100
9
+ fotolab/subcommands/env.py,sha256=JamU3a2xWPbwlAj5iThHs58KYkLmjpUphZfTQODBp_4,1471
10
+ fotolab/subcommands/halftone.py,sha256=RNEdXqRbBK7-OnBJzVb1Jglr4uaq5RsgVCy9hDoo7S0,2748
11
+ fotolab/subcommands/info.py,sha256=DANbfBNy2SzFfeE4KqOViAZkaME6xujfZvJTHIaZyCY,3312
12
+ fotolab/subcommands/montage.py,sha256=hhRH9LsWxXa86_qtVDKGvk--Eap2nP17OTy81kq3Xjk,2048
13
+ fotolab/subcommands/resize.py,sha256=d2Nlslzlvri9L2rqmE-HbmnLozylSk3U1Hi3DF1q3Mc,5023
14
+ fotolab/subcommands/rotate.py,sha256=vhtiAD5r0i5humpjyAbkoxh2nQsSuBYUD-TgcECwUwE,2149
15
+ fotolab/subcommands/sharpen.py,sha256=xz8RW8cRPM4eUvJTO1Stsur3G67DBftVGza8kF5j2Pc,3700
16
+ fotolab/subcommands/watermark.py,sha256=zKIFMreqSRaTD89JPjtLZljfTw-5ZkbZNBAyLeFveGw,8905
17
+ fotolab-0.26.0.dist-info/entry_points.txt,sha256=mvw7AY_yZkIyjAxPtHNed9X99NZeLnMxEeAfEJUbrCM,44
18
+ fotolab-0.26.0.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
19
+ fotolab-0.26.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
20
+ fotolab-0.26.0.dist-info/METADATA,sha256=CEe3EMlbCTfCuvSe_5MbbQueLiVl5XxI0NP2FTpfY3k,11058
21
+ fotolab-0.26.0.dist-info/RECORD,,
@@ -1,20 +0,0 @@
1
- fotolab/__init__.py,sha256=xMgr0qY4XC9waGeCumA3xk1SjuwsIC0tuMY3k_u0suU,2061
2
- fotolab/__main__.py,sha256=aboOURPs_snOXTEWYR0q8oq1UTY9e-NxCd1j33V0wHI,833
3
- fotolab/cli.py,sha256=vUS7eVcwEy2CWn4g5wTujLXS_GAzug9Np7j8-sM6GHU,4321
4
- fotolab/subcommands/__init__.py,sha256=5ncuu_LxuWphjNohm32Z_lD0FmJPWrAynBzeza0lyCU,1124
5
- fotolab/subcommands/animate.py,sha256=ejimhTozo9DN7BbqqcV4x8zLnanZRKq1pxBBFeOdr6Q,2967
6
- fotolab/subcommands/auto.py,sha256=ljvC0Z88Dva18YHyn3auAjlvVHqGrxsky-HGXwaIMZo,2391
7
- fotolab/subcommands/border.py,sha256=5ch2d7LVPhB2OFuuXSW5ci6Cn967CPDQu0qSfaO7uMg,3591
8
- fotolab/subcommands/contrast.py,sha256=l7Bs5p8W8ypN9Cg3fFHnU-A20UwMKtjTiPk6D0PRwpM,2095
9
- fotolab/subcommands/env.py,sha256=6vQDQ1sunJl2XBaSAHpLZUOiKiHy4STO45CMjXJd_Ow,1466
10
- fotolab/subcommands/info.py,sha256=vDzomRfHOKCNk9TON5CX9UB_km6GYBJT_nkDcwtARVA,3330
11
- fotolab/subcommands/montage.py,sha256=lUVY-zDSH7mwH-s34_XefdNp7CoDJHkwpbTUGiyJGgs,2037
12
- fotolab/subcommands/resize.py,sha256=2bH1Kgoe_DqU8ozJ1E_oA6a9JPtuwIlo5a4sq_4Yles,5018
13
- fotolab/subcommands/rotate.py,sha256=27Xrc8iV9n8WI6tOE-vBBMUeSYu2CtZAh-PGcF7JL-k,2144
14
- fotolab/subcommands/sharpen.py,sha256=wUPtJdtB6mCRmcHrA0CoEVO0O0ROBJWhejTvUeL67QU,2655
15
- fotolab/subcommands/watermark.py,sha256=5vsMDeJZhLT5qmftJQXY4jK2gtPQsbTYKXA6Ye2MqmA,8900
16
- fotolab-0.24.0.dist-info/entry_points.txt,sha256=mvw7AY_yZkIyjAxPtHNed9X99NZeLnMxEeAfEJUbrCM,44
17
- fotolab-0.24.0.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
18
- fotolab-0.24.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
19
- fotolab-0.24.0.dist-info/METADATA,sha256=VH-jJMrow1yoLw1XXO4eVgl1putj9tJuLFd93Tg9MSE,10975
20
- fotolab-0.24.0.dist-info/RECORD,,