Skip to content

Commit

Permalink
Merge pull request #29 from vgalin/v1.1.3
Browse files Browse the repository at this point in the history
V1.1.3
  • Loading branch information
vgalin authored Jun 16, 2021
2 parents 4d184dc + 4c85802 commit cc5b39c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
7 changes: 4 additions & 3 deletions html2image/html2image.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ def screenshot(
self.load_str(content=content, as_filename=html_filename)
self.screenshot_loaded_file(
file=html_filename,
output_file=name
output_file=name,
size=current_size,
)

screenshot_paths.append(os.path.join(self.output_path, name))
Expand All @@ -631,7 +632,7 @@ def screenshot(
self.screenshot_loaded_file(
file=os.path.basename(screenshot_target),
output_file=name,
size=current_size
size=current_size,
)
else:
raise FileNotFoundError(screenshot_target)
Expand All @@ -645,7 +646,7 @@ def screenshot(
self.screenshot_url(
url=target_url,
output_file=name,
size=current_size
size=current_size,
)
screenshot_paths.append(os.path.join(self.output_path, name))

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "html2image"
version = "1.1.2"
version = "1.1.3"
description = "Package acting as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files."
authors = ["vgalin"]
license = "MIT"
Expand Down
48 changes: 45 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_screenshot_url_custom_sizes():

for wanted_size, path in zip(test_sizes, paths):
img = Image.open(path)
assert wanted_size == img.size # default size
assert wanted_size == img.size


def test_screenshot_url_sizes_missing_custom_names():
Expand All @@ -87,7 +87,7 @@ def test_screenshot_url_sizes_missing_custom_names():

for wanted_size, path in zip(test_sizes, paths):
img = Image.open(path)
assert wanted_size == img.size # default size
assert wanted_size == img.size


def test_screenshot_string():
Expand All @@ -109,6 +109,28 @@ def test_screenshot_string():
assert pixels[0, 0] == (0, 0, 255, 255) # blue + no transparency


def test_screenshot_string_different_sizes():
hti = Html2Image(output_path=OUTPUT_PATH)

test_sizes = [
(100, 100),
(100, 1000),
(100, 200),
]

html = "Hello"

paths = hti.screenshot(
html_str=[html]*3,
save_as="from_string_custom_size.png",
size=test_sizes
)

for wanted_size, path in zip(test_sizes, paths):
img = Image.open(path)
assert wanted_size == img.size


def test_screenshot_other_svg():
hti = Html2Image(output_path=OUTPUT_PATH)

Expand All @@ -125,7 +147,7 @@ def test_screenshot_other_svg():
assert pixels[0, 0] == (0, 0, 0, 0) # full transparency no color


def test_screensshot_file():
def test_screenshot_file():
hti = Html2Image(output_path=OUTPUT_PATH)

paths = hti.screenshot(
Expand All @@ -143,6 +165,26 @@ def test_screensshot_file():
assert pixels[0, 0] == (0, 0, 255, 255) # blue + no transparency


def test_screenshot_file_different_sizes():
hti = Html2Image(output_path=OUTPUT_PATH)

test_sizes = [
(100, 100),
(100, 1000),
(100, 200),
]

paths = hti.screenshot(
html_file=["./examples/blue_page.html"]*3,
save_as="from_file_custom_size.png",
size=test_sizes
)

for wanted_size, path in zip(test_sizes, paths):
img = Image.open(path)
assert wanted_size == img.size


def test_extend_size_param():
hti = Html2Image(output_path=OUTPUT_PATH)

Expand Down

0 comments on commit cc5b39c

Please sign in to comment.