Skip to content

Commit ae2aff3

Browse files
committed
Change screenshot sizes
For correct screenshot we need to set the viewport. The PR bedrockio/export-html#8 for the container is still not merged, therefore we do the patch before building it.
1 parent 315a229 commit ae2aff3

10 files changed

+100
-9
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
From ab5317ff94fb6340917bf460953951eb5e2411d9 Mon Sep 17 00:00:00 2001
2+
From: Kevin Fullerton <kevin.fullerton1980@gmail.com>
3+
Date: Thu, 2 May 2024 11:23:45 +0000
4+
Subject: [PATCH] Added ability to set the viewport and associated options when
5+
requesting a screenshot using the Puppeteer Page.setVIewport() method
6+
7+
---
8+
src/app.js | 14 ++++++++++++++
9+
1 file changed, 14 insertions(+)
10+
11+
diff --git a/src/app.js b/src/app.js
12+
index 0c4c6a0..9337998 100644
13+
--- a/src/app.js
14+
+++ b/src/app.js
15+
@@ -55,6 +55,7 @@ router.post(
16+
type: yd.string().allow("jpeg", "png", "webp").default("png"),
17+
quality: yd.number().min(0).max(100).default(100),
18+
fullPage: yd.boolean().default(true),
19+
+ fromSurface: yd.boolean().default(true),
20+
clip: yd.object({
21+
x: yd.number(),
22+
y: yd.number(),
23+
@@ -63,6 +64,14 @@ router.post(
24+
}),
25+
omitBackground: yd.boolean().default(false),
26+
encoding: yd.string().allow("base64", "binary").default("binary"),
27+
+ viewport: yd.object({
28+
+ width: yd.number().default(800),
29+
+ height: yd.number().default(600),
30+
+ deviceScaleFactory: yd.number().default(1),
31+
+ hasTouch: yd.boolean().default(false),
32+
+ isLandscape: yd.boolean().default(false),
33+
+ isMobile: yd.boolean().default(false),
34+
+ }),
35+
})
36+
.default({
37+
scale: 1,
38+
@@ -78,6 +87,11 @@ router.post(
39+
const browser = await getBrowser();
40+
const page = await browser.newPage();
41+
42+
+ if (body.export.viewport) {
43+
+ await page.setViewport(body.export.viewport);
44+
+ delete body.export.viewport;
45+
+ }
46+
+
47+
if (body.url) {
48+
await page.goto(body.url, { waitUntil: "load" });
49+
} else {
50+
--
51+
2.50.1 (Apple Git-155)
52+
20.1 KB
Loading
19.9 KB
Loading
21.8 KB
Loading
13.2 KB
Loading
12.1 KB
Loading
12 KB
Loading
13.4 KB
Loading

doc/images/screenshot-html.jpeg

17.3 KB
Loading

noxfile.py

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,44 @@ def html2jpeg(session: nox.Session) -> None:
559559
"""Create JPEGs from HTML for documentation"""
560560
import requests # pylint: disable=import-outside-toplevel
561561

562+
session.log("Build patched image of bedrockio/export-html...")
563+
with session.chdir(session.cache_dir):
564+
if not Path("export-html").exists():
565+
session.run(
566+
"git",
567+
"clone",
568+
"https://github.com/bedrockio/export-html.git",
569+
external=True,
570+
)
571+
with session.chdir("export-html"):
572+
session.run(
573+
"git",
574+
"checkout",
575+
"228f0fdf42cc31f1269f31f015e94e0b1f423c6d",
576+
"--",
577+
".",
578+
external=True,
579+
)
580+
session.run("git", "reset", "--hard", external=True)
581+
session.run(
582+
"git",
583+
"apply",
584+
str(
585+
Path(__file__).parent
586+
/ "admin"
587+
/ "0001-Added-ability-to-set-the-viewport-and-associated-opt.patch"
588+
),
589+
external=True,
590+
)
591+
session.run(
592+
"docker",
593+
"build",
594+
"-t",
595+
"bedrockio/export-html-patched",
596+
".",
597+
external=True,
598+
)
599+
562600
# Create a socket
563601
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
564602
# Bind the socket to localhost and let the OS assign a free port number
@@ -577,7 +615,7 @@ def html2jpeg(session: nox.Session) -> None:
577615
"--detach",
578616
"-p",
579617
f"{port}:2305",
580-
"bedrockio/export-html",
618+
"bedrockio/export-html-patched",
581619
]
582620
).strip()
583621

@@ -603,6 +641,7 @@ def read_file(file: str) -> str:
603641
"type": "jpeg",
604642
"fullPage": False,
605643
"clip": {"x": 1, "y": 1, "width": size[0], "height": size[1]},
644+
"viewport": {"width": size[0], "height": size[1]},
606645
},
607646
}
608647
session.log(f"Generating {jpeg} from {html}...")
@@ -631,42 +670,42 @@ def read_file(file: str) -> str:
631670
screenshot(
632671
"doc/examples/example_html.html",
633672
"doc/images/screenshot-html.jpeg",
634-
(800, 290),
673+
(1000, 375),
635674
)
636675
screenshot(
637676
"doc/examples/example_html.details.example.cpp.9597a7a3397b8e3a48116e2a3afb4154.html",
638677
"doc/images/screenshot-html-details.example.cpp.jpeg",
639-
(800, 600),
678+
(1000, 660),
640679
)
641680
screenshot(
642681
"tests/html/reference/theme-default-green/gcc-5/coverage.main.cpp.118fcbaaba162ba17933c7893247df3a.html",
643682
"doc/images/screenshot-html-default-green-src.jpeg",
644-
(800, 290),
683+
(1000, 390),
645684
)
646685
screenshot(
647686
"tests/html/reference/theme-default-blue/gcc-5/coverage.main.cpp.118fcbaaba162ba17933c7893247df3a.html",
648687
"doc/images/screenshot-html-default-blue-src.jpeg",
649-
(800, 290),
688+
(1000, 390),
650689
)
651690
screenshot(
652691
"tests/html/reference/theme-github-green/gcc-5/coverage.main.cpp.118fcbaaba162ba17933c7893247df3a.html",
653692
"doc/images/screenshot-html-github-green-src.jpeg",
654-
(800, 500),
693+
(1150, 460),
655694
)
656695
screenshot(
657696
"tests/html/reference/theme-github-blue/gcc-5/coverage.main.cpp.118fcbaaba162ba17933c7893247df3a.html",
658697
"doc/images/screenshot-html-github-blue-src.jpeg",
659-
(800, 500),
698+
(1150, 460),
660699
)
661700
screenshot(
662701
"tests/html/reference/theme-github-dark-green/gcc-5/coverage.main.cpp.118fcbaaba162ba17933c7893247df3a.html",
663702
"doc/images/screenshot-html-github-dark-green-src.jpeg",
664-
(800, 500),
703+
(1150, 460),
665704
)
666705
screenshot(
667706
"tests/html/reference/theme-github-dark-blue/gcc-5/coverage.main.cpp.118fcbaaba162ba17933c7893247df3a.html",
668707
"doc/images/screenshot-html-github-dark-blue-src.jpeg",
669-
(800, 500),
708+
(1150, 460),
670709
)
671710

672711

0 commit comments

Comments
 (0)