fotolab 0.26.2__tar.gz → 0.27.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.
- {fotolab-0.26.2 → fotolab-0.27.0}/.coveragerc +0 -1
- {fotolab-0.26.2 → fotolab-0.27.0}/.pre-commit-config.yaml +1 -1
- {fotolab-0.26.2 → fotolab-0.27.0}/CHANGELOG.md +15 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/PKG-INFO +1 -1
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/__init__.py +1 -1
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/cli.py +4 -1
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/border.py +17 -7
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/halftone.py +45 -28
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/montage.py +3 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/rotate.py +2 -6
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/watermark.py +22 -46
- {fotolab-0.26.2 → fotolab-0.27.0}/noxfile.py +3 -1
- {fotolab-0.26.2 → fotolab-0.27.0}/.gitignore +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/.python-version +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/CONTRIBUTING.md +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/LICENSE.md +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/Pipfile +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/Pipfile.lock +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/README.md +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/Makefile +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/make.bat +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/source/CHANGELOG.md +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/source/CONTRIBUTING.md +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/source/LICENSE.md +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/source/README.md +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/source/_static/logo.jpg +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/source/conf.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/docs/source/index.rst +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/__main__.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/__init__.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/animate.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/auto.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/contrast.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/env.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/info.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/resize.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/fotolab/subcommands/sharpen.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/pyproject.toml +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/tests/__init__.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/tests/conftest.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/tests/test_env_subcommand.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/tests/test_help_flag.py +0 -0
- {fotolab-0.26.2 → fotolab-0.27.0}/tests/test_quiet_flag.py +0 -0
@@ -7,6 +7,21 @@ and this project adheres to [0-based versioning](https://0ver.org/).
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## v0.27.0 (2025-02-16)
|
11
|
+
|
12
|
+
- Explicitly name the attribute for the subcommand
|
13
|
+
- Refactor rotation calculation
|
14
|
+
- Set coverage to use parallel mode
|
15
|
+
- Use ast.Constant as ast.Str is deprecated for python 3.8+
|
16
|
+
- Use bicubic resampling when rotating image
|
17
|
+
- Validate that two images needed for montage subcommand
|
18
|
+
|
19
|
+
## v0.26.3 (2025-02-09)
|
20
|
+
|
21
|
+
- Bump `pre-commit` hooks
|
22
|
+
- Refactor text generation or saving image for `watermark` subcommand
|
23
|
+
- Refactor `halftone` and `border` subcommand
|
24
|
+
|
10
25
|
## v0.26.2 (2025-02-02)
|
11
26
|
|
12
27
|
- Add missing changelog item
|
@@ -129,7 +129,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
129
129
|
version=f"%(prog)s {__version__}",
|
130
130
|
)
|
131
131
|
|
132
|
-
subparsers = parser.add_subparsers(
|
132
|
+
subparsers = parser.add_subparsers(
|
133
|
+
help="sub-command help",
|
134
|
+
dest="command",
|
135
|
+
)
|
133
136
|
fotolab.subcommands.build_subparser(subparsers)
|
134
137
|
|
135
138
|
return parser
|
@@ -125,13 +125,23 @@ def run(args: argparse.Namespace) -> None:
|
|
125
125
|
save_image(args, bordered_image, image_filename, "border")
|
126
126
|
|
127
127
|
|
128
|
-
def get_border(args: argparse.Namespace) -> tuple:
|
129
|
-
"""Calculate the border.
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
def get_border(args: argparse.Namespace) -> tuple[int, int, int, int]:
|
129
|
+
"""Calculate the border dimensions.
|
130
|
+
|
131
|
+
Args:
|
132
|
+
args (argparse.Namespace): Command line arguments
|
133
|
+
|
134
|
+
Returns:
|
135
|
+
tuple[int, int, int, int]: Border dimensions in pixesl. If individual
|
136
|
+
widths are not specified, returns a uniform width for all sides.
|
137
|
+
"""
|
138
|
+
if any(
|
139
|
+
[
|
140
|
+
args.width_left,
|
141
|
+
args.width_top,
|
142
|
+
args.width_right,
|
143
|
+
args.width_bottom,
|
144
|
+
]
|
135
145
|
):
|
136
146
|
return (
|
137
147
|
int(args.width_left),
|
@@ -67,45 +67,62 @@ def run(args: argparse.Namespace) -> None:
|
|
67
67
|
|
68
68
|
for image_filename in args.image_filenames:
|
69
69
|
original_image = Image.open(image_filename)
|
70
|
-
|
71
|
-
|
70
|
+
halftone_image = create_halftone_image(original_image)
|
71
|
+
|
72
|
+
if args.before_after:
|
73
|
+
save_gif_image(
|
74
|
+
args, image_filename, original_image, halftone_image
|
75
|
+
)
|
76
|
+
else:
|
77
|
+
save_image(args, halftone_image, image_filename, "halftone")
|
72
78
|
|
73
|
-
halftone_image = Image.new("L", (width, height), "black")
|
74
|
-
draw = ImageDraw.Draw(halftone_image)
|
75
79
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
rowtotal = math.ceil(height / cellsize)
|
80
|
+
def create_halftone_image(
|
81
|
+
original_image: Image.Image, cell_count: int = 50
|
82
|
+
) -> Image.Image:
|
83
|
+
"""Create a halftone version of the input image.
|
81
84
|
|
82
|
-
|
83
|
-
|
85
|
+
Modified from the circular halftone effect processing.py example from
|
86
|
+
https://tabreturn.github.io/code/processing/python/2019/02/09/processing.py_in_ten_lessons-6.3-_halftones.html
|
84
87
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
col += 1
|
88
|
+
Args:
|
89
|
+
original_image: The source image to convert
|
90
|
+
cell_count: Number of cells across the width (default: 50)
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
Returns:
|
93
|
+
Image.Image: The halftone converted image
|
94
|
+
"""
|
95
|
+
grayscale_image = original_image.convert("L")
|
96
|
+
width, height = original_image.size
|
93
97
|
|
94
|
-
|
95
|
-
|
98
|
+
halftone_image = Image.new("L", (width, height), "black")
|
99
|
+
draw = ImageDraw.Draw(halftone_image)
|
96
100
|
|
101
|
+
cellsize = width / cell_count
|
102
|
+
rowtotal = math.ceil(height / cellsize)
|
103
|
+
|
104
|
+
for row in range(rowtotal):
|
105
|
+
for col in range(cell_count):
|
106
|
+
# Calculate center point of current cell
|
107
|
+
x = int(col * cellsize + cellsize / 2)
|
108
|
+
y = int(row * cellsize + cellsize / 2)
|
109
|
+
|
110
|
+
# Get brightness and calculate dot size
|
97
111
|
brightness = grayscale_image.getpixel((x, y))
|
98
|
-
|
112
|
+
dot_size = 10 * brightness / 200
|
113
|
+
|
114
|
+
# Draw the dot
|
99
115
|
draw.ellipse(
|
100
|
-
[
|
116
|
+
[
|
117
|
+
x - dot_size / 2,
|
118
|
+
y - dot_size / 2,
|
119
|
+
x + dot_size / 2,
|
120
|
+
y + dot_size / 2,
|
121
|
+
],
|
122
|
+
fill=255,
|
101
123
|
)
|
102
124
|
|
103
|
-
|
104
|
-
save_gif_image(
|
105
|
-
args, image_filename, original_image, halftone_image
|
106
|
-
)
|
107
|
-
else:
|
108
|
-
save_image(args, halftone_image, image_filename, "halftone")
|
125
|
+
return halftone_image
|
109
126
|
|
110
127
|
|
111
128
|
def save_gif_image(args, image_filename, original_image, sharpen_image):
|
@@ -57,6 +57,9 @@ def run(args: argparse.Namespace) -> None:
|
|
57
57
|
for image_filename in args.image_filenames:
|
58
58
|
images.append(Image.open(image_filename.name))
|
59
59
|
|
60
|
+
if len(images) < 2:
|
61
|
+
raise ValueError("At least two images is required for montage")
|
62
|
+
|
60
63
|
total_width = sum(img.width for img in images)
|
61
64
|
total_height = max(img.height for img in images)
|
62
65
|
|
@@ -67,14 +67,10 @@ def run(args: argparse.Namespace) -> None:
|
|
67
67
|
"""
|
68
68
|
log.debug(args)
|
69
69
|
|
70
|
-
rotation = args.rotation
|
71
|
-
if args.clockwise:
|
72
|
-
rotation = -rotation
|
73
|
-
|
70
|
+
rotation = -args.rotation if args.clockwise else args.rotation
|
74
71
|
for image_filename in args.image_filenames:
|
75
72
|
original_image = Image.open(image_filename)
|
76
73
|
rotated_image = original_image.rotate(
|
77
|
-
rotation,
|
78
|
-
expand=True,
|
74
|
+
rotation, expand=True, resample=Image.Resampling.BICUBIC
|
79
75
|
)
|
80
76
|
save_image(args, rotated_image, image_filename, "rotate")
|
@@ -167,46 +167,10 @@ def run(args: argparse.Namespace) -> None:
|
|
167
167
|
|
168
168
|
def watermark_gif_image(original_image: Image.Image, args: argparse.Namespace):
|
169
169
|
"""Watermark the image."""
|
170
|
-
watermarked_image = original_image.copy()
|
171
|
-
|
172
170
|
frames = []
|
173
|
-
|
174
171
|
for frame in ImageSequence.Iterator(original_image):
|
175
|
-
|
176
|
-
|
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)
|
172
|
+
watermarked_frame = watermark_image(args, frame.convert("RGBA"))
|
173
|
+
frames.append(watermarked_frame)
|
210
174
|
|
211
175
|
frames[0].save(
|
212
176
|
"foo.gif",
|
@@ -223,20 +187,20 @@ def watermark_non_gif_image(
|
|
223
187
|
original_image: Image.Image, args: argparse.Namespace
|
224
188
|
):
|
225
189
|
"""Watermark the image."""
|
226
|
-
|
190
|
+
return watermark_image(args, original_image)
|
191
|
+
|
227
192
|
|
193
|
+
def watermark_image(
|
194
|
+
args: argparse.Namespace, original_image: Image.Image
|
195
|
+
) -> Image.Image:
|
196
|
+
"""Watermark an image."""
|
197
|
+
watermarked_image = original_image.copy()
|
228
198
|
draw = ImageDraw.Draw(watermarked_image)
|
229
199
|
|
230
200
|
font = ImageFont.load_default(calc_font_size(original_image, args))
|
231
201
|
log.debug("default font: %s", " ".join(font.getname()))
|
232
202
|
|
233
|
-
text = args
|
234
|
-
if args.camera and camera_metadata(original_image):
|
235
|
-
text = camera_metadata(original_image)
|
236
|
-
|
237
|
-
if args.lowercase:
|
238
|
-
text = text.lower()
|
239
|
-
|
203
|
+
text = prepare_text(args, original_image)
|
240
204
|
(left, top, right, bottom) = draw.textbbox(xy=(0, 0), text=text, font=font)
|
241
205
|
text_width = right - left
|
242
206
|
text_height = bottom - top
|
@@ -259,6 +223,18 @@ def watermark_non_gif_image(
|
|
259
223
|
return watermarked_image
|
260
224
|
|
261
225
|
|
226
|
+
def prepare_text(args, image) -> str:
|
227
|
+
"""Prepare the watermark text."""
|
228
|
+
text = args.text
|
229
|
+
if args.camera and camera_metadata(image):
|
230
|
+
text = camera_metadata(image)
|
231
|
+
|
232
|
+
if args.lowercase:
|
233
|
+
text = text.lower()
|
234
|
+
|
235
|
+
return text
|
236
|
+
|
237
|
+
|
262
238
|
def calc_font_size(image, args) -> int:
|
263
239
|
"""Calculate the font size based on the width of the image."""
|
264
240
|
width, _height = image.size
|
@@ -133,7 +133,9 @@ def release(session: nox.Session) -> None:
|
|
133
133
|
for node in ast.walk(tree):
|
134
134
|
if isinstance(node, ast.Assign) and len(node.targets) == 1:
|
135
135
|
target, value = node.targets[0], node.value
|
136
|
-
if target.id == "__version__" and isinstance(
|
136
|
+
if target.id == "__version__" and isinstance(
|
137
|
+
value, ast.Constant
|
138
|
+
):
|
137
139
|
current_version = value.s
|
138
140
|
break
|
139
141
|
|
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
|
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
|