fotolab 0.23.0__py3-none-any.whl → 0.25.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
@@ -21,7 +21,7 @@ import subprocess
21
21
  import sys
22
22
  from pathlib import Path
23
23
 
24
- __version__ = "0.23.0"
24
+ __version__ = "0.25.0"
25
25
 
26
26
  log = logging.getLogger(__name__)
27
27
 
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
@@ -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
@@ -44,9 +44,9 @@ def run(_args: argparse.Namespace) -> None:
44
44
  None
45
45
  """
46
46
  sys_version = sys.version.replace("\n", "")
47
- print(
47
+ env = [
48
48
  f"fotolab: {__version__}",
49
49
  f"python: {sys_version}",
50
50
  f"platform: {platform.platform()}",
51
- sep="\n",
52
- )
51
+ ]
52
+ print(*env, sep="\n")
@@ -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
@@ -73,18 +73,20 @@ def run(args: argparse.Namespace) -> None:
73
73
  None
74
74
  """
75
75
  log.debug(args)
76
+
76
77
  info = []
78
+ image = Image.open(args.image_filename)
77
79
 
78
80
  if args.camera:
79
- info.append(camera_metadata(args.image_filename))
81
+ info.append(camera_metadata(image))
80
82
 
81
83
  if args.datetime:
82
- info.append(datetime(args.image_filename))
84
+ info.append(datetime(image))
83
85
 
84
86
  if info:
85
87
  print("\n".join(info))
86
88
  else:
87
- exif_tags = extract_exif_tags(args.image_filename)
89
+ exif_tags = extract_exif_tags(image)
88
90
  if exif_tags:
89
91
  tag_name_width = max(map(len, exif_tags))
90
92
  for tag_name, tag_value in exif_tags.items():
@@ -93,9 +95,8 @@ def run(args: argparse.Namespace) -> None:
93
95
  print("No metadata found!")
94
96
 
95
97
 
96
- def extract_exif_tags(image_filename: str, sort: bool = False) -> dict:
98
+ def extract_exif_tags(image: Image.Image, sort: bool = False) -> dict:
97
99
  """Extract Exif metadata from image."""
98
- image = Image.open(image_filename)
99
100
  exif = image._getexif()
100
101
  log.debug(exif)
101
102
 
@@ -112,14 +113,14 @@ def extract_exif_tags(image_filename: str, sort: bool = False) -> dict:
112
113
  return filtered_info
113
114
 
114
115
 
115
- def datetime(image_filename):
116
+ def datetime(image: Image.Image):
116
117
  """Extract datetime metadata."""
117
- exif_tags = extract_exif_tags(image_filename)
118
+ exif_tags = extract_exif_tags(image)
118
119
  return exif_tags["DateTime"]
119
120
 
120
121
 
121
- def camera_metadata(image_filename):
122
+ def camera_metadata(image: Image.Image):
122
123
  """Extract camera and model metadata."""
123
- exif_tags = extract_exif_tags(image_filename)
124
+ exif_tags = extract_exif_tags(image)
124
125
  metadata = f'{exif_tags["Make"]} {exif_tags["Model"]}'
125
126
  return metadata.strip()
@@ -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
@@ -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
@@ -19,7 +19,7 @@ import argparse
19
19
  import logging
20
20
  import math
21
21
 
22
- from PIL import Image, ImageColor, ImageDraw, ImageFont
22
+ from PIL import Image, ImageColor, ImageDraw, ImageFont, ImageSequence
23
23
 
24
24
  from fotolab import save_image
25
25
  from fotolab.subcommands.info import camera_metadata
@@ -157,13 +157,72 @@ def run(args: argparse.Namespace) -> None:
157
157
  log.debug(args)
158
158
 
159
159
  for image_filename in args.image_filenames:
160
- watermarked_image = watermark_image(image_filename, args)
161
- save_image(args, watermarked_image, image_filename, "watermark")
160
+ image = Image.open(image_filename)
161
+ if image.format == "GIF":
162
+ watermark_gif_image(image, args)
163
+ else:
164
+ watermarked_image = watermark_non_gif_image(image, args)
165
+ save_image(args, watermarked_image, image_filename, "watermark")
162
166
 
163
167
 
164
- def watermark_image(image_filename, args):
168
+ def watermark_gif_image(original_image: Image.Image, args: argparse.Namespace):
169
+ """Watermark the image."""
170
+ watermarked_image = original_image.copy()
171
+
172
+ frames = []
173
+
174
+ for frame in ImageSequence.Iterator(original_image):
175
+ frame = frame.convert("RGBA")
176
+ draw = ImageDraw.Draw(frame)
177
+
178
+ font = ImageFont.load_default(calc_font_size(original_image, args))
179
+ log.debug("default font: %s", " ".join(font.getname()))
180
+
181
+ text = args.text
182
+ if args.camera and camera_metadata(original_image):
183
+ text = camera_metadata(original_image)
184
+
185
+ if args.lowercase:
186
+ text = text.lower()
187
+
188
+ (left, top, right, bottom) = draw.textbbox(
189
+ xy=(0, 0), text=text, font=font
190
+ )
191
+ text_width = right - left
192
+ text_height = bottom - top
193
+ (position_x, position_y) = calc_position(
194
+ watermarked_image,
195
+ text_width,
196
+ text_height,
197
+ args.position,
198
+ calc_padding(original_image, args),
199
+ )
200
+
201
+ draw.text(
202
+ (position_x, position_y),
203
+ text,
204
+ font=font,
205
+ fill=(*ImageColor.getrgb(args.font_color), 128),
206
+ stroke_width=calc_font_outline_width(original_image, args),
207
+ stroke_fill=(*ImageColor.getrgb(args.outline_color), 128),
208
+ )
209
+ frames.append(frame)
210
+
211
+ frames[0].save(
212
+ "foo.gif",
213
+ format="GIF",
214
+ append_images=frames[1:],
215
+ save_all=True,
216
+ duration=original_image.info.get("duration", 100),
217
+ loop=original_image.info.get("loop", 0),
218
+ disposal=original_image.info.get("disposal", 2),
219
+ )
220
+
221
+
222
+ def watermark_non_gif_image(
223
+ original_image: Image.Image, args: argparse.Namespace
224
+ ):
165
225
  """Watermark the image."""
166
- original_image = Image.open(image_filename)
167
226
  watermarked_image = original_image.copy()
168
227
 
169
228
  draw = ImageDraw.Draw(watermarked_image)
@@ -172,8 +231,8 @@ def watermark_image(image_filename, args):
172
231
  log.debug("default font: %s", " ".join(font.getname()))
173
232
 
174
233
  text = args.text
175
- if args.camera and camera_metadata(image_filename):
176
- text = camera_metadata(image_filename)
234
+ if args.camera and camera_metadata(original_image):
235
+ text = camera_metadata(original_image)
177
236
 
178
237
  if args.lowercase:
179
238
  text = text.lower()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fotolab
3
- Version: 0.23.0
3
+ Version: 0.25.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>
@@ -385,7 +385,7 @@ options:
385
385
 
386
386
  ## Copyright and License
387
387
 
388
- Copyright (C) 2024 Kian-Meng Ang
388
+ Copyright (C) 2024,2025 Kian-Meng Ang
389
389
 
390
390
  This program is free software: you can redistribute it and/or modify it under
391
391
  the terms of the GNU Affero General Public License as published by the Free
@@ -0,0 +1,20 @@
1
+ fotolab/__init__.py,sha256=Q-uGtGYhMgsiocBd99EGzDzXlP7ak1kfVRvKyNAsh-o,2066
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=_W4K_D0eOiE30iIhlfyXCoeqF47q7adh82TeWMywR5I,3596
8
+ fotolab/subcommands/contrast.py,sha256=8uPCd5xI-aUsL7rjdEPmfSskdzMwM-1tv0eRRONkW2M,2100
9
+ fotolab/subcommands/env.py,sha256=JamU3a2xWPbwlAj5iThHs58KYkLmjpUphZfTQODBp_4,1471
10
+ fotolab/subcommands/info.py,sha256=DANbfBNy2SzFfeE4KqOViAZkaME6xujfZvJTHIaZyCY,3312
11
+ fotolab/subcommands/montage.py,sha256=MwZ0z7oWFAElIE3Kh7VQxQRtvcb0n97Q65PGK9ab0SY,2042
12
+ fotolab/subcommands/resize.py,sha256=d2Nlslzlvri9L2rqmE-HbmnLozylSk3U1Hi3DF1q3Mc,5023
13
+ fotolab/subcommands/rotate.py,sha256=vhtiAD5r0i5humpjyAbkoxh2nQsSuBYUD-TgcECwUwE,2149
14
+ fotolab/subcommands/sharpen.py,sha256=xz8RW8cRPM4eUvJTO1Stsur3G67DBftVGza8kF5j2Pc,3700
15
+ fotolab/subcommands/watermark.py,sha256=zKIFMreqSRaTD89JPjtLZljfTw-5ZkbZNBAyLeFveGw,8905
16
+ fotolab-0.25.0.dist-info/entry_points.txt,sha256=mvw7AY_yZkIyjAxPtHNed9X99NZeLnMxEeAfEJUbrCM,44
17
+ fotolab-0.25.0.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
18
+ fotolab-0.25.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
19
+ fotolab-0.25.0.dist-info/METADATA,sha256=jmNKiKHpBzNMQf6LDqKs2qElLlXLtDRad1PoRcdpSrw,10980
20
+ fotolab-0.25.0.dist-info/RECORD,,
@@ -1,20 +0,0 @@
1
- fotolab/__init__.py,sha256=kuoG8pds6QFs3Dr-rEOqncyEAq-1X7KN5yIR2TBcn90,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=fzUoRWgYEiYJIWYEiiSLEb7dH_xVUOnhMpQgc1yjrTY,1457
10
- fotolab/subcommands/info.py,sha256=bkB41ZB5BewUCvY5XBn21D1pOyLcTjsI10dseYEARfE,3354
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=1-5gpVCHYd7myZtsPWrrwcubTFDBdDzFmth7TSfBAgM,7073
16
- fotolab-0.23.0.dist-info/entry_points.txt,sha256=mvw7AY_yZkIyjAxPtHNed9X99NZeLnMxEeAfEJUbrCM,44
17
- fotolab-0.23.0.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
18
- fotolab-0.23.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
19
- fotolab-0.23.0.dist-info/METADATA,sha256=L0KRYDKyddFDqwFLtfYhkgI45P7JzVnVEaFnlMbY8Ms,10975
20
- fotolab-0.23.0.dist-info/RECORD,,