Skip to content

Commit cc5b39c

Browse files
authored
Merge pull request #29 from vgalin/v1.1.3
V1.1.3
2 parents 4d184dc + 4c85802 commit cc5b39c

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

html2image/html2image.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ def screenshot(
616616
self.load_str(content=content, as_filename=html_filename)
617617
self.screenshot_loaded_file(
618618
file=html_filename,
619-
output_file=name
619+
output_file=name,
620+
size=current_size,
620621
)
621622

622623
screenshot_paths.append(os.path.join(self.output_path, name))
@@ -631,7 +632,7 @@ def screenshot(
631632
self.screenshot_loaded_file(
632633
file=os.path.basename(screenshot_target),
633634
output_file=name,
634-
size=current_size
635+
size=current_size,
635636
)
636637
else:
637638
raise FileNotFoundError(screenshot_target)
@@ -645,7 +646,7 @@ def screenshot(
645646
self.screenshot_url(
646647
url=target_url,
647648
output_file=name,
648-
size=current_size
649+
size=current_size,
649650
)
650651
screenshot_paths.append(os.path.join(self.output_path, name))
651652

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "html2image"
3-
version = "1.1.2"
3+
version = "1.1.3"
44
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."
55
authors = ["vgalin"]
66
license = "MIT"

tests/test_main.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_screenshot_url_custom_sizes():
6060

6161
for wanted_size, path in zip(test_sizes, paths):
6262
img = Image.open(path)
63-
assert wanted_size == img.size # default size
63+
assert wanted_size == img.size
6464

6565

6666
def test_screenshot_url_sizes_missing_custom_names():
@@ -87,7 +87,7 @@ def test_screenshot_url_sizes_missing_custom_names():
8787

8888
for wanted_size, path in zip(test_sizes, paths):
8989
img = Image.open(path)
90-
assert wanted_size == img.size # default size
90+
assert wanted_size == img.size
9191

9292

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

111111

112+
def test_screenshot_string_different_sizes():
113+
hti = Html2Image(output_path=OUTPUT_PATH)
114+
115+
test_sizes = [
116+
(100, 100),
117+
(100, 1000),
118+
(100, 200),
119+
]
120+
121+
html = "Hello"
122+
123+
paths = hti.screenshot(
124+
html_str=[html]*3,
125+
save_as="from_string_custom_size.png",
126+
size=test_sizes
127+
)
128+
129+
for wanted_size, path in zip(test_sizes, paths):
130+
img = Image.open(path)
131+
assert wanted_size == img.size
132+
133+
112134
def test_screenshot_other_svg():
113135
hti = Html2Image(output_path=OUTPUT_PATH)
114136

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

127149

128-
def test_screensshot_file():
150+
def test_screenshot_file():
129151
hti = Html2Image(output_path=OUTPUT_PATH)
130152

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

145167

168+
def test_screenshot_file_different_sizes():
169+
hti = Html2Image(output_path=OUTPUT_PATH)
170+
171+
test_sizes = [
172+
(100, 100),
173+
(100, 1000),
174+
(100, 200),
175+
]
176+
177+
paths = hti.screenshot(
178+
html_file=["./examples/blue_page.html"]*3,
179+
save_as="from_file_custom_size.png",
180+
size=test_sizes
181+
)
182+
183+
for wanted_size, path in zip(test_sizes, paths):
184+
img = Image.open(path)
185+
assert wanted_size == img.size
186+
187+
146188
def test_extend_size_param():
147189
hti = Html2Image(output_path=OUTPUT_PATH)
148190

0 commit comments

Comments
 (0)