Skip to content

Commit 6255416

Browse files
author
Nutchanon Ninyawee
committed
Enhance CLI and core functionality with improved resolution and rendering support
- Updated CLI to support more flexible resolution handling - Added support for screen and print media resolution types - Introduced new resolution classes: ScreenResolution and PrintMediaResolution - Enhanced render timeout and scale factor handling - Updated tests to cover new CLI and core functionality - Bumped version to 0.6.0 to reflect significant changes - Added Pydantic as a dependency for improved type validation - Simplified CLI argument parsing and processing - Improved error handling and parameter flexibility
1 parent f73e488 commit 6255416

File tree

9 files changed

+576
-396
lines changed

9 files changed

+576
-396
lines changed

.mise.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ run = "uv run ruff check snap_html/ tests/"
3838

3939
[tasks.build]
4040
description = "Build package"
41-
sources = ["snap_html"]
41+
sources = ["snap_html/**/*.py", "pyproject.toml", "README.md", "LICENSE"]
4242
outputs = ["dist"]
4343
run = "rm -rf dist && uv build"
4444

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.5.1] - 2023-10-15
11+
1012
### Added
1113

1214
- Command Line Interface (CLI) for capturing screenshots
@@ -15,16 +17,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1517
- New PrintMediaResolution type that combines pixel and CM dimensions
1618
- Object-fit options (contain, cover, fill, none) for controlling how content fits in viewport
1719
- Optional resolution parameter with sensible defaults
20+
- CLI support for render_timeout parameter to control waiting for RENDER_COMPLETE signal
21+
- CLI support for object_fit parameter to control content fitting
1822

1923
### Fixed
2024

2125
- Fixed unit conversion in UnitConverter class to properly handle Pint quantity objects
2226
- Improved DPI and resolution handling for more accurate image sizing
2327
- Fixed type checking issues with resolution parameters
28+
- Fixed type handling in CLI for better compatibility with the core functions
29+
- Improved error handling in CLI for nonexistent files
2430

2531
### Changed
2632

2733
- Adjusted default device scale factor to 1.5 (150% zoom) for better image quality
2834
- Modified resolution handling to support both screen and print media dimensions
2935
- Made resolution parameter optional with sensible defaults
3036
- Made object_fit parameter optional with a default value of "contain"
37+
- Updated CLI tests to properly test all parameters and edge cases

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,16 @@ screenshot = generate_image_sync(
263263
"dpi": 300,
264264
"object_fit": "contain"
265265
},
266-
scale_factor=1.5 # Increase zoom level for sharper text
266+
scale_factor=1.5, # Increase zoom level for sharper text
267+
render_timeout=10.0 # Wait up to 10 seconds for RENDER_COMPLETE signal
268+
)
269+
270+
# Using object_fit as a separate parameter
271+
screenshot = generate_image_sync(
272+
"https://www.example.com",
273+
resolution={"width": 1920, "height": 1080},
274+
object_fit="cover", # Content will cover the entire viewport
275+
scale_factor=1.5
267276
)
268277
```
269278

@@ -309,19 +318,19 @@ If the `RENDER_COMPLETE` signal is not received within the specified timeout, sn
309318

310319
```bash
311320
# Basic usage with pixel dimensions
312-
snap-html capture https://example.com -o screenshot.png --width 1920 --height 1080
321+
snap-html https://example.com -o screenshot.png --width 1920 --height 1080
313322

314323
# Using physical dimensions (e.g., A4 paper size)
315-
snap-html capture input.html --cm-width 21.0 --cm-height 29.7 --dpi 300 -o output.png
324+
snap-html input.html --cm-width 21.0 --cm-height 29.7 --dpi 300 -o output.png
316325

317326
# Capture with custom scale factor
318-
snap-html capture https://example.com -o screenshot.png --width 1024 --height 768 --scale 2.0
327+
snap-html https://example.com -o screenshot.png --width 1024 --height 768 --scale 2.0
319328

320329
# Using both pixel and physical dimensions with object-fit
321-
snap-html capture https://example.com -o screenshot.png --width 1920 --height 1080 --cm-width 21.0 --cm-height 29.7 --object-fit cover
330+
snap-html https://example.com -o screenshot.png --width 1920 --height 1080 --cm-width 21.0 --cm-height 29.7 --object-fit cover
322331

323332
# Wait for RENDER_COMPLETE signal with custom timeout
324-
snap-html capture https://example.com -o screenshot.png --render-timeout 15.0
333+
snap-html https://example.com -o screenshot.png --timeout 15.0
325334
```
326335

327336
**Available Options**:
@@ -333,8 +342,8 @@ snap-html capture https://example.com -o screenshot.png --render-timeout 15.0
333342
--cm-height FLOAT Output height in centimeters
334343
--dpi INTEGER DPI for cm-based resolution [default: 300]
335344
--scale FLOAT Browser scale factor (zoom level) [default: 1.5]
336-
--object-fit TEXT How content fits viewport: contain, cover, fill, none [default: contain]
337-
--render-timeout FLOAT Time to wait for RENDER_COMPLETE signal (in seconds) [default: 10.0]
345+
--timeout FLOAT Time to wait for RENDER_COMPLETE signal (in seconds)
346+
--object-fit TEXT How content fits viewport: contain, cover, fill, none
338347
--help Show this message and exit.
339348
```
340349

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "snap-html"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
description = "a robust, modern and high performance Python library for generating image from a html string/html file/url build on top of `playwright`"
55
authors = [{ name = "codustry", email = "[email protected]" }]
66
requires-python = "~=3.8"
@@ -20,6 +20,7 @@ dependencies = [
2020
"furl>=2.1.0",
2121
"pint>=0.21.1",
2222
"pytest>=6.2.5",
23+
"pydantic>=2.10.6",
2324
]
2425

2526
[project.urls]
@@ -89,8 +90,6 @@ exclude = [
8990
"venv",
9091
]
9192

92-
[tool.ruff.lint]
93-
docstring-code-line-length = "dynamic"
9493

9594
[tool.ruff.lint.per-file-ignores]
9695
"__init__.py" = ["E402"]

0 commit comments

Comments
 (0)