fotolab 0.21.1__py3-none-any.whl → 0.22.1__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
@@ -21,7 +21,7 @@ import subprocess
21
21
  import sys
22
22
  from pathlib import Path
23
23
 
24
- __version__ = "0.21.1"
24
+ __version__ = "0.22.1"
25
25
 
26
26
  log = logging.getLogger(__name__)
27
27
 
fotolab/cli.py CHANGED
@@ -23,19 +23,9 @@
23
23
  import argparse
24
24
  import logging
25
25
  import sys
26
- from typing import Dict, Optional, Sequence
27
-
28
- import fotolab.animate
29
- import fotolab.auto
30
- import fotolab.border
31
- import fotolab.contrast
32
- import fotolab.env
33
- import fotolab.info
34
- import fotolab.montage
35
- import fotolab.resize
36
- import fotolab.rotate
37
- import fotolab.sharpen
38
- import fotolab.watermark
26
+ from typing import Optional, Sequence
27
+
28
+ import fotolab.subcommands
39
29
  from fotolab import __version__
40
30
 
41
31
  log = logging.getLogger(__name__)
@@ -49,18 +39,17 @@ def setup_logging(args: argparse.Namespace) -> None:
49
39
  if args.quiet:
50
40
  logging.disable(logging.NOTSET)
51
41
  else:
52
- conf: Dict = {
53
- True: {
54
- "level": logging.DEBUG,
55
- "msg": "[%(asctime)s] %(levelname)s: %(name)s: %(message)s",
56
- },
57
- False: {"level": logging.INFO, "msg": "%(message)s"},
58
- }
42
+ level = logging.DEBUG if args.debug else logging.INFO
43
+ format_string = (
44
+ "[%(asctime)s] %(levelname)s: %(name)s: %(message)s"
45
+ if args.debug
46
+ else "%(message)s"
47
+ )
59
48
 
60
49
  logging.basicConfig(
61
- level=conf[args.debug]["level"],
50
+ level=level,
51
+ format=format_string,
62
52
  stream=sys.stdout,
63
- format=conf[args.debug]["msg"],
64
53
  datefmt="%Y-%m-%d %H:%M:%S",
65
54
  )
66
55
 
@@ -136,17 +125,7 @@ def build_parser() -> argparse.ArgumentParser:
136
125
  )
137
126
 
138
127
  subparsers = parser.add_subparsers(help="sub-command help")
139
- fotolab.animate.build_subparser(subparsers)
140
- fotolab.auto.build_subparser(subparsers)
141
- fotolab.border.build_subparser(subparsers)
142
- fotolab.contrast.build_subparser(subparsers)
143
- fotolab.info.build_subparser(subparsers)
144
- fotolab.resize.build_subparser(subparsers)
145
- fotolab.rotate.build_subparser(subparsers)
146
- fotolab.montage.build_subparser(subparsers)
147
- fotolab.sharpen.build_subparser(subparsers)
148
- fotolab.watermark.build_subparser(subparsers)
149
- fotolab.env.build_subparser(subparsers)
128
+ fotolab.subcommands.build_subparser(subparsers)
150
129
 
151
130
  return parser
152
131
 
@@ -0,0 +1,32 @@
1
+ # Copyright (C) 2024 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
+ """Common utils for subcommand."""
17
+
18
+ import importlib
19
+ import pkgutil
20
+
21
+
22
+ def build_subparser(subparsers):
23
+ """Build subparser for each subcommands."""
24
+ iter_namespace = pkgutil.iter_modules(__path__, __name__ + ".")
25
+
26
+ subcommands = {
27
+ name: importlib.import_module(name)
28
+ for finder, name, ispkg in iter_namespace
29
+ }
30
+
31
+ for subcommand in subcommands.values():
32
+ subcommand.build_subparser(subparsers)
@@ -18,10 +18,10 @@
18
18
  import argparse
19
19
  import logging
20
20
 
21
- import fotolab.contrast
22
- import fotolab.resize
23
- import fotolab.sharpen
24
- import fotolab.watermark
21
+ import fotolab.subcommands.contrast
22
+ import fotolab.subcommands.resize
23
+ import fotolab.subcommands.sharpen
24
+ import fotolab.subcommands.watermark
25
25
 
26
26
  log = logging.getLogger(__name__)
27
27
 
@@ -77,7 +77,7 @@ def run(args: argparse.Namespace) -> None:
77
77
  log.debug(args)
78
78
  log.debug(combined_args)
79
79
 
80
- fotolab.resize.run(combined_args)
81
- fotolab.contrast.run(combined_args)
82
- fotolab.sharpen.run(combined_args)
83
- fotolab.watermark.run(combined_args)
80
+ fotolab.subcommands.resize.run(combined_args)
81
+ fotolab.subcommands.contrast.run(combined_args)
82
+ fotolab.subcommands.sharpen.run(combined_args)
83
+ fotolab.subcommands.watermark.run(combined_args)
@@ -54,6 +54,14 @@ def build_subparser(subparsers) -> None:
54
54
  help="show the camera maker details",
55
55
  )
56
56
 
57
+ info_parser.add_argument(
58
+ "--datetime",
59
+ default=False,
60
+ action="store_true",
61
+ dest="datetime",
62
+ help="show the datetime",
63
+ )
64
+
57
65
 
58
66
  def run(args: argparse.Namespace) -> None:
59
67
  """Run info subcommand.
@@ -65,8 +73,16 @@ def run(args: argparse.Namespace) -> None:
65
73
  None
66
74
  """
67
75
  log.debug(args)
76
+ info = []
77
+
68
78
  if args.camera:
69
- print(camera_metadata(args.image_filename))
79
+ info.append(camera_metadata(args.image_filename))
80
+
81
+ if args.datetime:
82
+ info.append(datetime(args.image_filename))
83
+
84
+ if info:
85
+ print("\n".join(info))
70
86
  else:
71
87
  exif_tags = extract_exif_tags(args.image_filename)
72
88
  if exif_tags:
@@ -96,6 +112,12 @@ def extract_exif_tags(image_filename: str, sort: bool = False) -> dict:
96
112
  return filtered_info
97
113
 
98
114
 
115
+ def datetime(image_filename):
116
+ """Extract datetime metadata."""
117
+ exif_tags = extract_exif_tags(image_filename)
118
+ return exif_tags["DateTime"]
119
+
120
+
99
121
  def camera_metadata(image_filename):
100
122
  """Extract camera and model metadata."""
101
123
  exif_tags = extract_exif_tags(image_filename)
@@ -22,7 +22,7 @@ import math
22
22
  from PIL import Image, ImageColor, ImageDraw, ImageFont
23
23
 
24
24
  from fotolab import save_image
25
- from fotolab.info import extract_exif_tags
25
+ from fotolab.subcommands.info import camera_metadata
26
26
 
27
27
  log = logging.getLogger(__name__)
28
28
 
@@ -139,7 +139,7 @@ def build_subparser(subparsers) -> None:
139
139
  "-l",
140
140
  "--lowercase",
141
141
  default=True,
142
- action="store_true",
142
+ action=argparse.BooleanOptionalAction,
143
143
  dest="lowercase",
144
144
  help="lowercase the watermark text",
145
145
  )
@@ -200,13 +200,6 @@ def watermark_image(image_filename, args):
200
200
  return watermarked_image
201
201
 
202
202
 
203
- def camera_metadata(image_filename):
204
- """Extract camera and model metadata."""
205
- exif_tags = extract_exif_tags(image_filename)
206
- metadata = f'{exif_tags["Make"]} {exif_tags["Model"]}'
207
- return metadata.strip()
208
-
209
-
210
203
  def calc_font_size(image, args) -> int:
211
204
  """Calculate the font size based on the width of the image."""
212
205
  width, _height = image.size
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fotolab
3
- Version: 0.21.1
3
+ Version: 0.22.1
4
4
  Summary: A console program that manipulate images.
5
5
  Keywords: photography,photo
6
6
  Author-email: Kian-Meng Ang <kianmeng@cpan.org>
@@ -206,7 +206,7 @@ fotolab info -h
206
206
  <!--help-info !-->
207
207
 
208
208
  ```console
209
- usage: fotolab info [-h] [-s] IMAGE_FILENAME
209
+ usage: fotolab info [-h] [-s] [--camera] IMAGE_FILENAME
210
210
 
211
211
  positional arguments:
212
212
  IMAGE_FILENAME set the image filename
@@ -214,6 +214,7 @@ positional arguments:
214
214
  options:
215
215
  -h, --help show this help message and exit
216
216
  -s, --sort show image info by sorted field name
217
+ --camera show the camera maker details
217
218
  ```
218
219
 
219
220
  <!--help-info !-->
@@ -326,7 +327,7 @@ usage: fotolab watermark [-h] [-t WATERMARK_TEXT]
326
327
  [-p {top-left,top-right,bottom-left,bottom-right}]
327
328
  [-pd PADDING] [-fs FONT_SIZE] [-fc FONT_COLOR]
328
329
  [-ow OUTLINE_WIDTH] [-oc OUTLINE_COLOR] [--camera]
329
- [-l]
330
+ [-l | --lowercase | --no-lowercase]
330
331
  IMAGE_FILENAMES [IMAGE_FILENAMES ...]
331
332
 
332
333
  positional arguments:
@@ -354,7 +355,8 @@ options:
354
355
  set the outline color of the watermark text (default:
355
356
  'black')
356
357
  --camera use camera metadata as watermark
357
- -l, --lowercase lowercase the watermark text
358
+ -l, --lowercase, --no-lowercase
359
+ lowercase the watermark text
358
360
  ```
359
361
 
360
362
  <!--help-watermark !-->
@@ -0,0 +1,20 @@
1
+ fotolab/__init__.py,sha256=xdrWwLKoyxvOtFkatJOEMd_hDaY3--OVKgHZh6wY0n8,2061
2
+ fotolab/__main__.py,sha256=aboOURPs_snOXTEWYR0q8oq1UTY9e-NxCd1j33V0wHI,833
3
+ fotolab/cli.py,sha256=L_N94EsPeM1Ev0B5iyVvt4HEo7JTBNdhLmGZhBRIDA4,4235
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=l_vQgf0IcI8AR1TSVsk4PrMZtJ3j_wpU77rKiGJ-KTA,1715
14
+ fotolab/subcommands/sharpen.py,sha256=wUPtJdtB6mCRmcHrA0CoEVO0O0ROBJWhejTvUeL67QU,2655
15
+ fotolab/subcommands/watermark.py,sha256=tUqZoGjZk_7XG8qo7OiedfgmDY08qAWRF1Gx2ihAHO0,7264
16
+ fotolab-0.22.1.dist-info/entry_points.txt,sha256=mvw7AY_yZkIyjAxPtHNed9X99NZeLnMxEeAfEJUbrCM,44
17
+ fotolab-0.22.1.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
18
+ fotolab-0.22.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
19
+ fotolab-0.22.1.dist-info/METADATA,sha256=-KmtwWES6ulcPrR5TSgBxYBowTgOejyQ9Mg0aMb3k0c,10724
20
+ fotolab-0.22.1.dist-info/RECORD,,
@@ -1,19 +0,0 @@
1
- fotolab/__init__.py,sha256=fZZb0I229_RXcxunCTP3flULzE0p48prsOWsvTqLkyM,2061
2
- fotolab/__main__.py,sha256=aboOURPs_snOXTEWYR0q8oq1UTY9e-NxCd1j33V0wHI,833
3
- fotolab/animate.py,sha256=ejimhTozo9DN7BbqqcV4x8zLnanZRKq1pxBBFeOdr6Q,2967
4
- fotolab/auto.py,sha256=l_-Kf5V5Anvwz1QV1ET-42YsDWEeHf_okHkXWOycWAI,2295
5
- fotolab/border.py,sha256=5ch2d7LVPhB2OFuuXSW5ci6Cn967CPDQu0qSfaO7uMg,3591
6
- fotolab/cli.py,sha256=FBFSeMNqcOiJ6MuAcy0qUvc9cscdFUG946HlWZXBPtY,4984
7
- fotolab/contrast.py,sha256=l7Bs5p8W8ypN9Cg3fFHnU-A20UwMKtjTiPk6D0PRwpM,2095
8
- fotolab/env.py,sha256=fzUoRWgYEiYJIWYEiiSLEb7dH_xVUOnhMpQgc1yjrTY,1457
9
- fotolab/info.py,sha256=lY9n6HDnlDyRVDTRqYwzxm5xgPSyh0P8N3ybnnNtNtw,2892
10
- fotolab/montage.py,sha256=lUVY-zDSH7mwH-s34_XefdNp7CoDJHkwpbTUGiyJGgs,2037
11
- fotolab/resize.py,sha256=2bH1Kgoe_DqU8ozJ1E_oA6a9JPtuwIlo5a4sq_4Yles,5018
12
- fotolab/rotate.py,sha256=l_vQgf0IcI8AR1TSVsk4PrMZtJ3j_wpU77rKiGJ-KTA,1715
13
- fotolab/sharpen.py,sha256=wUPtJdtB6mCRmcHrA0CoEVO0O0ROBJWhejTvUeL67QU,2655
14
- fotolab/watermark.py,sha256=-YzxABVT5KJM1GgYLP3Z8X9YPfQzncOA9YnRJgNN6nA,7457
15
- fotolab-0.21.1.dist-info/entry_points.txt,sha256=mvw7AY_yZkIyjAxPtHNed9X99NZeLnMxEeAfEJUbrCM,44
16
- fotolab-0.21.1.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
17
- fotolab-0.21.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
18
- fotolab-0.21.1.dist-info/METADATA,sha256=hH4mutSmdcXzZmt204mH0EdmgErcY18WK8KR9wtjw5o,10600
19
- fotolab-0.21.1.dist-info/RECORD,,
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes