proofsheet 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +25 -124
- data/Rakefile +9 -0
- data/USAGE.md +408 -0
- data/examples/01_simple.yml +9 -0
- data/examples/02_targets_and_clipping.yml +16 -0
- data/examples/03_authentication.yml +29 -0
- data/examples/04_fetching_images.yml +19 -0
- data/examples/05_compositions.yml +48 -0
- data/examples/assets/logo.svg +12 -0
- data/examples/assets/logo480.png +0 -0
- data/examples/assets/wordmark_960_104.png +0 -0
- data/examples/output/avo_dashboard.png +0 -0
- data/examples/output/cat_badge.png +0 -0
- data/examples/output/cat_placeholder.png +0 -0
- data/examples/output/contact_sheet_lead.png +0 -0
- data/examples/output/fascination_logo.png +0 -0
- data/examples/output/homepage.png +0 -0
- data/examples/output/sample_page.png +0 -0
- data/examples/output/showcase.png +0 -0
- data/examples/output/web_page.png +0 -0
- data/lib/proofsheet/browser.rb +11 -0
- data/lib/proofsheet/capturer.rb +38 -7
- data/lib/proofsheet/cli.rb +7 -1
- data/lib/proofsheet/composer.rb +1 -1
- data/lib/proofsheet/composition_config.rb +7 -4
- data/lib/proofsheet/download.rb +27 -0
- data/lib/proofsheet/image_config.rb +43 -0
- data/lib/proofsheet/manifest.rb +24 -0
- data/lib/proofsheet/version.rb +1 -1
- data/lib/proofsheet.rb +2 -0
- metadata +22 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 234b0c63a2f6605f90b645c9f1b0f0edea3d57f14c9b4a9957ccd3ac26d20cf1
|
|
4
|
+
data.tar.gz: 7fc0d9240630bdfe9126eca40b4ba64113bdb69ed3f0bb1734dda1fb7c01dccb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae87dcc521208176985d9d990ab7061d19d30d0df7ac22bb92d01c6cc186b2f5977ac38aa4486daa6e4fea812522244a8954136e31559cf307fb982f1fa0c735
|
|
7
|
+
data.tar.gz: 430df63a9d720cde283a68e970e8c6c58f84f8851a37c907ce5679da14d1562239c2aba8b51b7fd9be50cbe86941408df937a423630cb35261b23e612fcb837e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.3.0] - 2026-11-30
|
|
4
|
+
|
|
5
|
+
- Add `images` for logos, watermarks, and other artwork Proofsheet did not capture, read from a local path, downloaded from a URL, or downloaded from an `<img>` selected on any webpage
|
|
6
|
+
- Draw them in compositions with `image:` layers, which take the same crop, resize, radius, rotation, and shadow options as `shot:` layers
|
|
7
|
+
|
|
3
8
|
## [0.2.0] - 2026-09-19
|
|
4
9
|
|
|
5
10
|
- Add the `compose` command for arranging captured screenshots on solid, transparent, gradient, or image backgrounds
|
data/README.md
CHANGED
|
@@ -1,164 +1,65 @@
|
|
|
1
1
|
# Proofsheet
|
|
2
2
|
|
|
3
|
-
Proofsheet captures repeatable screenshots from web applications
|
|
3
|
+
Proofsheet captures repeatable screenshots from web applications and assembles them into polished image compositions. A YAML manifest describes what to capture; the `proofsheet` CLI runs it in headless Chrome and writes PNG files.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
Install the gem:
|
|
8
|
-
|
|
9
7
|
```sh
|
|
10
8
|
gem install proofsheet
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
Proofsheet requires
|
|
11
|
+
Proofsheet requires Ruby 3.2 or newer, Chrome, and libvips.
|
|
14
12
|
|
|
15
|
-
##
|
|
13
|
+
## Quick start
|
|
16
14
|
|
|
17
|
-
Create `proofsheet.yml` in
|
|
15
|
+
Create `proofsheet.yml` in your project:
|
|
18
16
|
|
|
19
17
|
```yaml
|
|
20
18
|
host: "https://example.com"
|
|
21
19
|
|
|
22
|
-
expect:
|
|
23
|
-
username: "demo@example.com"
|
|
24
|
-
|
|
25
|
-
credentials:
|
|
26
|
-
username: "env:PROOFSHEET_USERNAME"
|
|
27
|
-
password: "env:PROOFSHEET_PASSWORD"
|
|
28
|
-
|
|
29
|
-
login:
|
|
30
|
-
path: "/sign-in"
|
|
31
|
-
username_field: "email"
|
|
32
|
-
password_field: "password"
|
|
33
|
-
submit: "Sign in"
|
|
34
|
-
expect:
|
|
35
|
-
selector: "header"
|
|
36
|
-
text: "demo@example.com"
|
|
37
|
-
|
|
38
|
-
targets:
|
|
39
|
-
account: 42
|
|
40
|
-
|
|
41
20
|
defaults:
|
|
42
21
|
viewport: [1440, 900]
|
|
43
22
|
output_dir: "docs/screenshots"
|
|
44
23
|
|
|
45
24
|
shots:
|
|
46
|
-
|
|
47
|
-
path: "/
|
|
48
|
-
wait_for: "[data-testid='dashboard']"
|
|
49
|
-
expect:
|
|
50
|
-
selector: ".account-name"
|
|
51
|
-
text: "Demo Account"
|
|
52
|
-
|
|
53
|
-
activity:
|
|
54
|
-
path: "/accounts/%{account}/activity"
|
|
55
|
-
wait_for: "[data-testid='activity-chart']"
|
|
56
|
-
click: "[data-range='7d']"
|
|
57
|
-
clip:
|
|
58
|
-
selector: "[data-testid='activity-chart']"
|
|
59
|
-
padding: 5
|
|
60
|
-
|
|
61
|
-
toolbar:
|
|
62
|
-
path: "/accounts/%{account}"
|
|
63
|
-
clip:
|
|
64
|
-
selector: ".toolbar"
|
|
65
|
-
full_width: true
|
|
25
|
+
homepage:
|
|
26
|
+
path: "/"
|
|
66
27
|
```
|
|
67
28
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Credential sources must be environment variables such as `env:PROOFSHEET_USERNAME` or 1Password secret references such as `op://Vault/Item/username`. Add `op_account` under `credentials` when 1Password needs an explicit account.
|
|
71
|
-
|
|
72
|
-
An `expect.username` value stops capture before Chrome starts if the loaded username is not the intended screenshot account. A login or shot-level `expect` stops capture when the expected text is absent from the selected element.
|
|
73
|
-
|
|
74
|
-
For pages whose final URL is only discoverable in the browser, `path_script` may contain JavaScript that returns a path. Set `resolved_wait_for` to wait for the destination content:
|
|
75
|
-
|
|
76
|
-
```yaml
|
|
77
|
-
shots:
|
|
78
|
-
latest-report:
|
|
79
|
-
path: "/reports"
|
|
80
|
-
wait_for: "[data-latest-report]"
|
|
81
|
-
path_script: "document.querySelector('[data-latest-report]').getAttribute('href')"
|
|
82
|
-
resolved_wait_for: "iframe[title='Report']"
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## CLI
|
|
86
|
-
|
|
87
|
-
Capture every shot:
|
|
29
|
+
Then capture it:
|
|
88
30
|
|
|
89
31
|
```sh
|
|
90
32
|
proofsheet capture
|
|
91
33
|
```
|
|
92
34
|
|
|
93
|
-
|
|
35
|
+
The main commands are:
|
|
94
36
|
|
|
95
37
|
```sh
|
|
96
|
-
proofsheet capture
|
|
97
|
-
proofsheet
|
|
98
|
-
proofsheet
|
|
38
|
+
proofsheet capture # Capture configured shots and fetched images
|
|
39
|
+
proofsheet compose # Build configured compositions
|
|
40
|
+
proofsheet list # List configured shots without opening Chrome
|
|
99
41
|
```
|
|
100
42
|
|
|
101
|
-
|
|
43
|
+
## Features
|
|
102
44
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Compositions arrange captured shots on a new PNG canvas. A background can be a solid color, an angled two-color gradient, or an image. Layers can be positioned, resized proportionally, rounded, rotated, and given a shadow.
|
|
112
|
-
|
|
113
|
-
```yaml
|
|
114
|
-
compositions:
|
|
115
|
-
launch-hero:
|
|
116
|
-
canvas: [1600, 1000]
|
|
117
|
-
background:
|
|
118
|
-
gradient: ["#211002", "#5aa579"]
|
|
119
|
-
angle: 135
|
|
120
|
-
layers:
|
|
121
|
-
- shot: dashboard
|
|
122
|
-
x: 120
|
|
123
|
-
y: 140
|
|
124
|
-
crop:
|
|
125
|
-
x: 80
|
|
126
|
-
y: 40
|
|
127
|
-
width: 1200
|
|
128
|
-
height: 700
|
|
129
|
-
width: 980
|
|
130
|
-
radius: 32
|
|
131
|
-
rotate: -4
|
|
132
|
-
shadow:
|
|
133
|
-
x: 8
|
|
134
|
-
y: 24
|
|
135
|
-
blur: 32
|
|
136
|
-
color: "#00000066"
|
|
137
|
-
- shot: activity
|
|
138
|
-
x: 900
|
|
139
|
-
y: 460
|
|
140
|
-
width: 560
|
|
141
|
-
rotate: 5
|
|
142
|
-
shadow: true
|
|
143
|
-
```
|
|
45
|
+
- Repeatable full-viewport and element-cropped screenshots driven by YAML
|
|
46
|
+
- Readiness selectors, scripted clicks, content assertions, target substitution, and browser-resolved paths
|
|
47
|
+
- Authenticated captures using environment variables or 1Password references, with identity safeguards
|
|
48
|
+
- Local image assets, direct URL downloads, and browser-selected `<img>` downloads using `currentSrc`
|
|
49
|
+
- Automatic conversion of downloaded images to PNG, including alpha transparency
|
|
50
|
+
- Compositions with solid, transparent, gradient, or image backgrounds
|
|
51
|
+
- Layer cropping, proportional resizing, rounded corners, rotation, positioning, and shadows
|
|
52
|
+
- Selective capture and composition from the command line
|
|
144
53
|
|
|
145
|
-
|
|
54
|
+
## Usage
|
|
146
55
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
Setting `shadow: true` uses `x: 0`, `y: 16`, `blur: 24`, and `color: "#00000055"`. Use the expanded shadow mapping shown above to override any of those values.
|
|
150
|
-
|
|
151
|
-
Capture the source shots, then compose every configured image or selected compositions:
|
|
152
|
-
|
|
153
|
-
```sh
|
|
154
|
-
proofsheet capture
|
|
155
|
-
proofsheet compose
|
|
156
|
-
proofsheet compose launch-hero
|
|
157
|
-
```
|
|
56
|
+
See [USAGE.md](USAGE.md) for the complete guide, runnable manifests, generated example images, and configuration reference.
|
|
158
57
|
|
|
159
58
|
## Development
|
|
160
59
|
|
|
161
|
-
Run `bin/setup`, then `bundle exec rake` to run the specs and linter.
|
|
60
|
+
Run `bin/setup`, then `bundle exec rake` to run the specs and linter. Regenerate the usage guide and its real example images with `bundle exec rake usage`.
|
|
61
|
+
|
|
62
|
+
To install the gem locally, run `bundle exec rake install`.
|
|
162
63
|
|
|
163
64
|
## License
|
|
164
65
|
|
data/Rakefile
CHANGED
|
@@ -10,3 +10,12 @@ require "rubocop/rake_task"
|
|
|
10
10
|
RuboCop::RakeTask.new
|
|
11
11
|
|
|
12
12
|
task default: %i[spec rubocop]
|
|
13
|
+
|
|
14
|
+
desc "Update USAGE.md with examples and generated images"
|
|
15
|
+
task :usage do
|
|
16
|
+
require "proofsheet"
|
|
17
|
+
require_relative "lib/proofsheet/usage_updater"
|
|
18
|
+
Proofsheet::UsageUpdater.new.update!
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
task docs: :usage
|
data/USAGE.md
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
# Proofsheet Usage Guide
|
|
2
|
+
|
|
3
|
+
Proofsheet automates capturing crisp, repeatable screenshots from web applications and assembling them into polished graphic compositions.
|
|
4
|
+
|
|
5
|
+
This guide walks through Proofsheet's features progressively, from a minimal single-shot capture to multi-layer marketing compositions with remote and local images. Every example is backed by a standalone YAML file in the `examples/` directory and can be updated using `bundle exec rake usage`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Command-Line Interface (CLI)
|
|
10
|
+
|
|
11
|
+
Proofsheet provides a single CLI binary with three primary commands:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
proofsheet capture [SHOT ...] [--config PATH] [--host HOST]
|
|
15
|
+
proofsheet compose [COMPOSITION ...] [--config PATH]
|
|
16
|
+
proofsheet list [--config PATH]
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- **`capture`**: Launches headless Chrome, logs in (if configured), navigates to shot URLs, clips elements, and downloads remote images. If no shot or image names are specified, all configured shots and remote images are captured.
|
|
20
|
+
- **`compose`**: Combines captured shots and assets onto defined canvases using libvips. If no composition names are provided, all configured compositions are built.
|
|
21
|
+
- **`list`**: Prints configured shot names and paths without launching Chrome.
|
|
22
|
+
- **`--config PATH`** (`-c PATH`): Specifies the manifest configuration file (defaults to `proofsheet.yml`).
|
|
23
|
+
- **`--host HOST`**: Overrides the base URL specified in the manifest.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 1. Simple Screenshot Capture
|
|
28
|
+
|
|
29
|
+
At its simplest, a Proofsheet manifest declares a `host` and a list of `shots`. Each shot must provide a `path` relative to `host`.
|
|
30
|
+
|
|
31
|
+
<!-- example: examples/01_simple.yml image: examples/output/homepage.png alt: "Example Domain Homepage" -->
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
host: "https://example.com"
|
|
35
|
+
|
|
36
|
+
defaults:
|
|
37
|
+
viewport: [1200, 800]
|
|
38
|
+
output_dir: "examples/output"
|
|
39
|
+
|
|
40
|
+
shots:
|
|
41
|
+
homepage:
|
|
42
|
+
path: "/"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
<!-- end-example -->
|
|
48
|
+
|
|
49
|
+
To run this capture:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
proofsheet capture --config examples/01_simple.yml
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This starts headless Chrome at the default viewport (`1200×800` as overridden under `defaults`), navigates to `https://example.com/`, waits for the page and web fonts to settle, and saves the full viewport to `examples/output/homepage.png`.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 2. Dynamic Targets and Element Clipping
|
|
60
|
+
|
|
61
|
+
When capturing documentation or marketing assets, you frequently want to focus on a specific component or UI element rather than the entire browser viewport. Proofsheet allows clipping shots directly to CSS selectors with optional padding.
|
|
62
|
+
|
|
63
|
+
Additionally, URL paths can include dynamic variable placeholders using `%{variable_name}`, which Proofsheet interpolates from the `targets` block.
|
|
64
|
+
|
|
65
|
+
<!-- example: examples/02_targets_and_clipping.yml image: examples/output/contact_sheet_lead.png alt: "Contact Print Wikipedia Element" -->
|
|
66
|
+
|
|
67
|
+
```yaml
|
|
68
|
+
host: "https://en.wikipedia.org"
|
|
69
|
+
|
|
70
|
+
targets:
|
|
71
|
+
article: "Contact_print"
|
|
72
|
+
|
|
73
|
+
defaults:
|
|
74
|
+
viewport: [1440, 900]
|
|
75
|
+
output_dir: "examples/output"
|
|
76
|
+
|
|
77
|
+
shots:
|
|
78
|
+
contact_sheet_lead:
|
|
79
|
+
path: "/wiki/%{article}"
|
|
80
|
+
wait_for: "#firstHeading"
|
|
81
|
+
clip:
|
|
82
|
+
selector: "figure"
|
|
83
|
+
padding: 8
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+

|
|
87
|
+
|
|
88
|
+
<!-- end-example -->
|
|
89
|
+
|
|
90
|
+
Key options used here:
|
|
91
|
+
- **`targets`**: Defines key-value pairs interpolated into `path` templates (e.g. `/wiki/%{article}` becomes `/wiki/Contact_print`).
|
|
92
|
+
- **`wait_for`**: Halts capture until the selector (`#firstHeading`) is rendered in the DOM.
|
|
93
|
+
- **`clip`**:
|
|
94
|
+
- `selector`: Computes the element's bounding box and crops the capture around it.
|
|
95
|
+
- `padding`: Adds spacing (in pixels) around all four sides of the element.
|
|
96
|
+
- `full_width`: (Optional, `true` or `false`) When `true`, expands the clip horizontally to fill the full viewport width while cropping vertically.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 3. Authenticated Sessions & Safety Expectations
|
|
101
|
+
|
|
102
|
+
Many web applications require authentication before screenshots can be taken. Proofsheet automates the login sequence through headless Chrome and protects against taking screenshots of the wrong account or broken states.
|
|
103
|
+
|
|
104
|
+
The example below runs against an online Ruby on Rails demo ([Avo](https://main.avodemo.com)):
|
|
105
|
+
|
|
106
|
+
<!-- example: examples/03_authentication.yml image: examples/output/avo_dashboard.png alt: "Authenticated Admin Dashboard" -->
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
host: "https://main.avodemo.com"
|
|
110
|
+
|
|
111
|
+
expect:
|
|
112
|
+
username: "avo@cado.com"
|
|
113
|
+
|
|
114
|
+
credentials:
|
|
115
|
+
username: "env:AVO_DEMO_USERNAME"
|
|
116
|
+
password: "env:AVO_DEMO_PASSWORD"
|
|
117
|
+
|
|
118
|
+
login:
|
|
119
|
+
path: "/users/sign_in"
|
|
120
|
+
username_field: "user_email"
|
|
121
|
+
password_field: "user_password"
|
|
122
|
+
submit: "Sign in"
|
|
123
|
+
expect:
|
|
124
|
+
selector: "body"
|
|
125
|
+
text: "Dashboards"
|
|
126
|
+
|
|
127
|
+
defaults:
|
|
128
|
+
viewport: [1280, 800]
|
|
129
|
+
output_dir: "examples/output"
|
|
130
|
+
|
|
131
|
+
shots:
|
|
132
|
+
avo_dashboard:
|
|
133
|
+
path: "/avo/dashboards/dashy"
|
|
134
|
+
wait_for: "main"
|
|
135
|
+
expect:
|
|
136
|
+
selector: "body"
|
|
137
|
+
text: "Dashy"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+

|
|
141
|
+
|
|
142
|
+
<!-- end-example -->
|
|
143
|
+
|
|
144
|
+
Security and verification mechanisms:
|
|
145
|
+
- **`credentials`**: Passwords and usernames are never written into the manifest. Instead, they reference environment variables (`env:VARIABLE_NAME`) or 1Password secrets (`op://vault/item/field`).
|
|
146
|
+
- **`expect.username`**: Verifies that the resolved username matches what the manifest author intended before Chrome ever boots.
|
|
147
|
+
- **`login`**: Instructs Proofsheet how to navigate to the sign-in page, fill in the credentials, and submit the form.
|
|
148
|
+
- **`expect`**: Assertions can be placed on the login form or on individual shots. If the specified `selector` does not contain the expected `text`, Proofsheet immediately aborts capture with an error instead of saving an invalid screenshot.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 4. Fetching External Images
|
|
153
|
+
|
|
154
|
+
Compositions often require assets that Proofsheet did not directly photograph, such as partner marks, avatars, product photos, or brand logos. Proofsheet supports an `images:` section with three distinct sources:
|
|
155
|
+
|
|
156
|
+
1. **`url`**: Downloads an image directly over HTTP or HTTPS without starting Chrome (e.g., placeholder images or CDNs).
|
|
157
|
+
2. **`page` & `selector`**: Boots headless Chrome, visits `page`, locates the matching `<img>` element, and fetches the browser-resolved `currentSrc` (useful when responsive `srcset` or dynamic JavaScript determines the actual image URL).
|
|
158
|
+
3. **`path`**: Points to a local file on disk, resolved relative to where `proofsheet` is executed. Local path images do not need to be captured.
|
|
159
|
+
|
|
160
|
+
<!-- example: examples/04_fetching_images.yml images: examples/output/cat_placeholder.png, examples/output/fascination_logo.png -->
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
host: "https://example.com"
|
|
164
|
+
|
|
165
|
+
defaults:
|
|
166
|
+
output_dir: "examples/output"
|
|
167
|
+
|
|
168
|
+
shots:
|
|
169
|
+
sample_page:
|
|
170
|
+
path: "/"
|
|
171
|
+
|
|
172
|
+
images:
|
|
173
|
+
cat_placeholder:
|
|
174
|
+
url: "https://placecats.com/300/200"
|
|
175
|
+
|
|
176
|
+
fascination_logo:
|
|
177
|
+
page: "https://fascination.works"
|
|
178
|
+
selector: ".site-logo img"
|
|
179
|
+
|
|
180
|
+
studio_logo:
|
|
181
|
+
path: "examples/assets/logo480.png"
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+

|
|
185
|
+
|
|
186
|
+

|
|
187
|
+
|
|
188
|
+
<!-- end-example -->
|
|
189
|
+
|
|
190
|
+
When running `proofsheet capture`, Proofsheet decodes the `url` and `page` images and writes them into the configured `output_dir` as real `<name>.png` files, retaining alpha transparency when the source has it.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 5. Multi-Layer Graphic Compositions
|
|
195
|
+
|
|
196
|
+
Once screenshots and images are captured, Proofsheet's composer arranges them onto a fresh canvas using high-performance libvips image processing.
|
|
197
|
+
|
|
198
|
+
Layers can be layered, resized proportionally, given rounded corners, rotated, and cast soft gaussian drop shadows.
|
|
199
|
+
|
|
200
|
+
<!-- example: examples/05_compositions.yml image: examples/output/showcase.png alt: "Multi-Layer Showcase Composition" -->
|
|
201
|
+
|
|
202
|
+
```yaml
|
|
203
|
+
host: "https://example.com"
|
|
204
|
+
|
|
205
|
+
defaults:
|
|
206
|
+
viewport: [800, 500]
|
|
207
|
+
output_dir: "examples/output"
|
|
208
|
+
|
|
209
|
+
shots:
|
|
210
|
+
web_page:
|
|
211
|
+
path: "/"
|
|
212
|
+
|
|
213
|
+
images:
|
|
214
|
+
cat_badge:
|
|
215
|
+
url: "https://placecats.com/300/300"
|
|
216
|
+
|
|
217
|
+
studio_logo:
|
|
218
|
+
path: "examples/assets/logo480.png"
|
|
219
|
+
|
|
220
|
+
compositions:
|
|
221
|
+
showcase:
|
|
222
|
+
canvas: [1200, 750]
|
|
223
|
+
background:
|
|
224
|
+
gradient: ["#1e293b", "#0f172a"]
|
|
225
|
+
angle: 135
|
|
226
|
+
layers:
|
|
227
|
+
- shot: web_page
|
|
228
|
+
x: 80
|
|
229
|
+
y: 100
|
|
230
|
+
width: 680
|
|
231
|
+
radius: 16
|
|
232
|
+
rotate: -2
|
|
233
|
+
shadow: true
|
|
234
|
+
|
|
235
|
+
- image: cat_badge
|
|
236
|
+
x: 740
|
|
237
|
+
y: 180
|
|
238
|
+
width: 360
|
|
239
|
+
radius: 24
|
|
240
|
+
rotate: 3
|
|
241
|
+
shadow:
|
|
242
|
+
x: 4
|
|
243
|
+
y: 20
|
|
244
|
+
blur: 28
|
|
245
|
+
color: "#00000066"
|
|
246
|
+
|
|
247
|
+
- image: studio_logo
|
|
248
|
+
x: 1040
|
|
249
|
+
y: 40
|
|
250
|
+
width: 100
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+

|
|
254
|
+
|
|
255
|
+
<!-- end-example -->
|
|
256
|
+
|
|
257
|
+
To build the composition:
|
|
258
|
+
|
|
259
|
+
```sh
|
|
260
|
+
# First ensure all source shots and remote images are captured:
|
|
261
|
+
proofsheet capture --config examples/05_compositions.yml
|
|
262
|
+
|
|
263
|
+
# Then generate the composition canvas:
|
|
264
|
+
proofsheet compose --config examples/05_compositions.yml
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Composition highlights:
|
|
268
|
+
- **`canvas`**: Defines `[width, height]` in pixels.
|
|
269
|
+
- **`background`**:
|
|
270
|
+
- Linear gradient: `gradient: ["#from", "#to"]` with an optional `angle:` in degrees.
|
|
271
|
+
- Solid color: `background: "#1e293b"` (supports 6-digit hex `#RRGGBB` or 8-digit hex `#RRGGBBAA` for alpha).
|
|
272
|
+
- Background image: `background: { image: "path/to/img.png" }` (automatically scaled and center-cropped to cover the canvas).
|
|
273
|
+
- **`layers`**:
|
|
274
|
+
- `shot:` references a captured shot name; `image:` references an image name.
|
|
275
|
+
- `x:` and `y:` coordinate positioning on the canvas.
|
|
276
|
+
- `width:` scales the layer proportionally to the specified pixel width.
|
|
277
|
+
- `radius:` rounds the layer's corners (clamped to half the smaller dimension).
|
|
278
|
+
- `rotate:` rotates the layer by degrees (with transparent background padding).
|
|
279
|
+
- `shadow: true`: applies a balanced drop shadow (`x: 0`, `y: 16`, `blur: 24`, `color: "#00000055"`). A custom mapping can override any of these parameters.
|
|
280
|
+
- `crop:` (optional) crops a sub-region `[x, y, width, height]` of the source screenshot before resizing.
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Complete YAML Manifest Reference
|
|
285
|
+
|
|
286
|
+
The table below documents every configuration key available in Proofsheet manifests.
|
|
287
|
+
|
|
288
|
+
### Top-Level Configuration
|
|
289
|
+
|
|
290
|
+
| Key | Type | Required | Description |
|
|
291
|
+
|---|---|---|---|
|
|
292
|
+
| `host` | String | Yes (or via `--host`) | Base URL for the target application (e.g. `https://example.com`). |
|
|
293
|
+
| `shots` | Mapping | Yes | Definitions of screenshots to capture. Each entry maps a shot name to its settings. |
|
|
294
|
+
| `images` | Mapping | No | Definitions of external or local image assets. |
|
|
295
|
+
| `compositions` | Mapping | No | Definitions of multi-layer canvas compositions. |
|
|
296
|
+
| `defaults` | Mapping | No | Global capture settings (see [Defaults](#defaults)). |
|
|
297
|
+
| `targets` | Mapping | No | Key-value dictionary used for dynamic variable substitution (`%{key}`) in shot paths. |
|
|
298
|
+
| `credentials` | Mapping | If `login` is set | Credential resolution sources (see [Credentials](#credentials)). |
|
|
299
|
+
| `login` | Mapping | No | Automated authentication form configuration (see [Login](#login)). |
|
|
300
|
+
| `expect` | Mapping | No | Global safety checks (e.g. `username:` verification). |
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
### `defaults`
|
|
305
|
+
|
|
306
|
+
| Key | Type | Default | Description |
|
|
307
|
+
|---|---|---|---|
|
|
308
|
+
| `viewport` | `[width, height]` | `[1440, 900]` | Initial browser window and viewport dimensions in pixels. |
|
|
309
|
+
| `output_dir` | String | `"screenshots"` | Directory where captured screenshots, fetched images, and compositions are written. Resolved relative to working directory. |
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
### `credentials`
|
|
314
|
+
|
|
315
|
+
| Key | Type | Required | Description |
|
|
316
|
+
|---|---|---|---|
|
|
317
|
+
| `username` | String | Yes | Source for the username. Must be `env:VAR_NAME` or `op://vault/item/field`. |
|
|
318
|
+
| `password` | String | Yes | Source for the password. Must be `env:VAR_NAME` or `op://vault/item/field`. |
|
|
319
|
+
| `op_account` | String | No | Optional 1Password account shorthand or sign-in address passed to `op read --account`. |
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
### `login`
|
|
324
|
+
|
|
325
|
+
| Key | Type | Required | Description |
|
|
326
|
+
|---|---|---|---|
|
|
327
|
+
| `path` | String | Yes | Path to the sign-in page relative to `host` (e.g. `"/users/sign_in"`). |
|
|
328
|
+
| `username_field` | String | Yes | Field name, HTML ID, or label for the username input. |
|
|
329
|
+
| `password_field` | String | Yes | Field name, HTML ID, or label for the password input. |
|
|
330
|
+
| `submit` | String | Yes | Button text, value, or ID to click to submit the sign-in form. |
|
|
331
|
+
| `expect` | Mapping | No | Post-login verification: `{ selector: "...", text: "..." }`. Ensures login completed before proceeding. |
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
### `shots.<name>`
|
|
336
|
+
|
|
337
|
+
| Key | Type | Required | Description |
|
|
338
|
+
|---|---|---|---|
|
|
339
|
+
| `path` | String | Yes | Path to visit. May contain `%{target}` tokens. |
|
|
340
|
+
| `wait_for` | String | No | CSS selector that must appear on the page before capturing. |
|
|
341
|
+
| `click` | String | No | CSS selector of an element to click before taking the screenshot. |
|
|
342
|
+
| `clip` | Mapping | No | Crop the screenshot to an element bounding box (see [Clip](#clip)). |
|
|
343
|
+
| `expect` | Mapping | No | Verify text presence: `{ selector: "...", text: "..." }`. |
|
|
344
|
+
| `path_script` | String | No | JavaScript expression evaluated in the browser returning a relative path. Useful for dynamic URLs. |
|
|
345
|
+
| `resolved_wait_for` | String | No | Selector to wait for after navigating to the path returned by `path_script`. |
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
### `clip`
|
|
350
|
+
|
|
351
|
+
| Key | Type | Default | Description |
|
|
352
|
+
|---|---|---|---|
|
|
353
|
+
| `selector` | String | Required | CSS selector of the element to measure and clip to. |
|
|
354
|
+
| `padding` | Integer | `0` | Padding in pixels added around the element's bounding rect. |
|
|
355
|
+
| `full_width` | Boolean | `false` | When `true`, clips vertically to the element while spanning the full viewport width. |
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
### `images.<name>`
|
|
360
|
+
|
|
361
|
+
Each image entry must set **exactly one** of `path`, `url`, or `page`:
|
|
362
|
+
|
|
363
|
+
| Key | Type | Description |
|
|
364
|
+
|---|---|---|
|
|
365
|
+
| `path` | String | Path to a local image file on disk. No capture step needed. |
|
|
366
|
+
| `url` | String | HTTP or HTTPS URL to download directly. |
|
|
367
|
+
| `page` | String | Webpage URL to visit in headless Chrome. Requires `selector`. |
|
|
368
|
+
| `selector` | String | CSS selector matching an `<img>` tag on `page`. Proofsheet reads its `currentSrc`. |
|
|
369
|
+
|
|
370
|
+
*Note: An image and a shot cannot share the same name because both write `<name>.png`.*
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
### `compositions.<name>`
|
|
375
|
+
|
|
376
|
+
| Key | Type | Required | Description |
|
|
377
|
+
|---|---|---|---|
|
|
378
|
+
| `canvas` | `[width, height]` | Yes | Canvas width and height in pixels. |
|
|
379
|
+
| `background` | String or Mapping | No (default: `"#ffffff"`) | Solid hex color (`"#ffffff"`), image mapping (`image: "path/to/bg.png"`), or gradient mapping (`gradient: ["#c1", "#c2"]`, `angle: 0..360`). |
|
|
380
|
+
| `layers` | Array of Mappings | Yes | List of layers drawn in order from back to front. |
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
### `compositions.<name>.layers[]`
|
|
385
|
+
|
|
386
|
+
Each layer must specify **exactly one** of `shot:` or `image:`:
|
|
387
|
+
|
|
388
|
+
| Key | Type | Default | Description |
|
|
389
|
+
|---|---|---|---|
|
|
390
|
+
| `shot` | String | - | Name of a captured shot to render. |
|
|
391
|
+
| `image` | String | - | Name of a configured image to render. |
|
|
392
|
+
| `x` | Integer | `0` | Horizontal coordinate on the canvas. |
|
|
393
|
+
| `y` | Integer | `0` | Vertical coordinate on the canvas. |
|
|
394
|
+
| `width` | Integer | Source width | Target display width in pixels. Height scales proportionally. |
|
|
395
|
+
| `radius` | Integer | `0` | Corner radius in pixels (applied after scaling). Clamped to half of the smaller dimension. |
|
|
396
|
+
| `rotate` | Integer / Float | `0` | Clockwise rotation angle in degrees. |
|
|
397
|
+
| `shadow` | Boolean or Mapping | `nil` | `true` for standard drop shadow, or `{ x: 0, y: 16, blur: 24, color: "#00000055" }`. |
|
|
398
|
+
| `crop` | Mapping | `nil` | Source cropping before scaling: `{ x: 0, y: 0, width: 800, height: 600 }`. |
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
## Updating Documentation
|
|
403
|
+
|
|
404
|
+
To re-run all examples and regenerate both the output images and markdown snippets:
|
|
405
|
+
|
|
406
|
+
```sh
|
|
407
|
+
bundle exec rake usage
|
|
408
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
host: "https://en.wikipedia.org"
|
|
2
|
+
|
|
3
|
+
targets:
|
|
4
|
+
article: "Contact_print"
|
|
5
|
+
|
|
6
|
+
defaults:
|
|
7
|
+
viewport: [1440, 900]
|
|
8
|
+
output_dir: "examples/output"
|
|
9
|
+
|
|
10
|
+
shots:
|
|
11
|
+
contact_sheet_lead:
|
|
12
|
+
path: "/wiki/%{article}"
|
|
13
|
+
wait_for: "#firstHeading"
|
|
14
|
+
clip:
|
|
15
|
+
selector: "figure"
|
|
16
|
+
padding: 8
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
host: "https://main.avodemo.com"
|
|
2
|
+
|
|
3
|
+
expect:
|
|
4
|
+
username: "avo@cado.com"
|
|
5
|
+
|
|
6
|
+
credentials:
|
|
7
|
+
username: "env:AVO_DEMO_USERNAME"
|
|
8
|
+
password: "env:AVO_DEMO_PASSWORD"
|
|
9
|
+
|
|
10
|
+
login:
|
|
11
|
+
path: "/users/sign_in"
|
|
12
|
+
username_field: "user_email"
|
|
13
|
+
password_field: "user_password"
|
|
14
|
+
submit: "Sign in"
|
|
15
|
+
expect:
|
|
16
|
+
selector: "body"
|
|
17
|
+
text: "Dashboards"
|
|
18
|
+
|
|
19
|
+
defaults:
|
|
20
|
+
viewport: [1280, 800]
|
|
21
|
+
output_dir: "examples/output"
|
|
22
|
+
|
|
23
|
+
shots:
|
|
24
|
+
avo_dashboard:
|
|
25
|
+
path: "/avo/dashboards/dashy"
|
|
26
|
+
wait_for: "main"
|
|
27
|
+
expect:
|
|
28
|
+
selector: "body"
|
|
29
|
+
text: "Dashy"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
host: "https://example.com"
|
|
2
|
+
|
|
3
|
+
defaults:
|
|
4
|
+
output_dir: "examples/output"
|
|
5
|
+
|
|
6
|
+
shots:
|
|
7
|
+
sample_page:
|
|
8
|
+
path: "/"
|
|
9
|
+
|
|
10
|
+
images:
|
|
11
|
+
cat_placeholder:
|
|
12
|
+
url: "https://placecats.com/300/200"
|
|
13
|
+
|
|
14
|
+
fascination_logo:
|
|
15
|
+
page: "https://fascination.works"
|
|
16
|
+
selector: ".site-logo img"
|
|
17
|
+
|
|
18
|
+
studio_logo:
|
|
19
|
+
path: "examples/assets/logo480.png"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
host: "https://example.com"
|
|
2
|
+
|
|
3
|
+
defaults:
|
|
4
|
+
viewport: [800, 500]
|
|
5
|
+
output_dir: "examples/output"
|
|
6
|
+
|
|
7
|
+
shots:
|
|
8
|
+
web_page:
|
|
9
|
+
path: "/"
|
|
10
|
+
|
|
11
|
+
images:
|
|
12
|
+
cat_badge:
|
|
13
|
+
url: "https://placecats.com/300/300"
|
|
14
|
+
|
|
15
|
+
studio_logo:
|
|
16
|
+
path: "examples/assets/logo480.png"
|
|
17
|
+
|
|
18
|
+
compositions:
|
|
19
|
+
showcase:
|
|
20
|
+
canvas: [1200, 750]
|
|
21
|
+
background:
|
|
22
|
+
gradient: ["#1e293b", "#0f172a"]
|
|
23
|
+
angle: 135
|
|
24
|
+
layers:
|
|
25
|
+
- shot: web_page
|
|
26
|
+
x: 80
|
|
27
|
+
y: 100
|
|
28
|
+
width: 680
|
|
29
|
+
radius: 16
|
|
30
|
+
rotate: -2
|
|
31
|
+
shadow: true
|
|
32
|
+
|
|
33
|
+
- image: cat_badge
|
|
34
|
+
x: 740
|
|
35
|
+
y: 180
|
|
36
|
+
width: 360
|
|
37
|
+
radius: 24
|
|
38
|
+
rotate: 3
|
|
39
|
+
shadow:
|
|
40
|
+
x: 4
|
|
41
|
+
y: 20
|
|
42
|
+
blur: 28
|
|
43
|
+
color: "#00000066"
|
|
44
|
+
|
|
45
|
+
- image: studio_logo
|
|
46
|
+
x: 1040
|
|
47
|
+
y: 40
|
|
48
|
+
width: 100
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
3
|
+
<svg width="100%" height="100%" viewBox="0 0 512 512" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
|
4
|
+
<g id="Logo" transform="matrix(2.056225,0,0,2.056225,-357.783133,-252.915663)">
|
|
5
|
+
<g transform="matrix(0.427835,0,0,0.427835,169.293814,116.582474)">
|
|
6
|
+
<path d="M593,51.375L593,560.625C593,580.701 576.701,597 556.625,597L47.375,597C27.299,597 11,580.701 11,560.625L11,51.375C11,31.299 27.299,15 47.375,15L556.625,15C576.701,15 593,31.299 593,51.375Z" style="fill:rgb(90,165,121);"/>
|
|
7
|
+
</g>
|
|
8
|
+
<g transform="matrix(0.300091,0,0,0.300091,148.942642,125.47191)">
|
|
9
|
+
<path d="M480.43,409.571C482.804,411.34 496.854,411.063 497.503,411.065C536.617,411.232 538.336,410.803 538.813,413.41C542.251,432.23 542.779,478.152 605.501,489.493C622.431,492.554 681.998,483.868 686.819,416.53C687.095,412.676 686.833,411.358 691.5,411.353C704.941,411.338 857.598,411.166 859.518,411.403C861.799,411.685 861.517,418.289 861.115,439.483C861.11,439.758 860.948,443.156 860.929,443.529C859.992,462.066 857.175,485.869 855.291,487.198C851.771,489.68 768.523,477.184 765.595,479.64C763.626,481.293 742.297,540.583 740.283,545.41C737.143,552.936 734.552,553.951 740.013,559.973C754.633,576.093 798.524,618.653 798.191,622.462C798.001,624.623 785.832,643.378 759.754,669.751C755.457,674.096 707.502,722.593 699.788,717.078C696.684,714.859 646.141,649.658 643.627,649.007C641.612,648.486 627.08,656.463 602.71,666.971C599.8,668.227 568.688,681.642 566.854,683.83C566.191,684.621 566.47,684.692 566.147,689.493C565.76,689.862 565.903,694.678 565.928,699.505C566.154,742.37 570.023,773.514 565.634,774.903C564.047,775.405 547.482,776.7 542.518,777.614C537.141,778.605 523.24,778.957 520.997,778.995C520.836,778.913 514.382,779.309 512.5,779.263C487.496,778.649 486.645,779.034 484.496,778.935C459.389,777.777 459.525,777.091 434.549,775.058C427.46,774.481 428.973,770.487 429.41,762.494C429.904,753.456 436.265,699.061 436.909,693.551C437.75,686.362 440.307,684.145 433.472,681.57C428.83,679.821 389.678,665.071 375.397,659.817C356.172,652.743 355.705,651.926 353.727,653.763C345.294,661.595 295.121,720.004 292.493,720.469C289.819,720.943 289.753,720.216 267.506,697.495C232.556,661.799 194.714,625.947 194.933,622.535C195.074,620.349 202.326,614.273 216.41,602.393C235.578,586.223 266.592,564.428 265.713,561.45C264.321,556.742 263.173,557.274 240.81,505.362C231.888,484.651 230.873,481.14 227.465,480.89C215.903,480.039 143.406,487.805 140.959,485.093C137.639,481.414 133.219,413.222 136.531,411.567C136.815,411.425 136.827,411.317 222.5,411.23C299.79,411.152 300.706,411.196 307.498,411.521C314.895,411.875 302.891,441.785 336.913,473.052C366.024,499.805 422.384,493.798 445.086,457.249C465.905,423.732 407.109,328.997 399.089,271.578C398.442,266.949 381.703,272.626 360.589,256.389C344.028,243.654 334.306,219.37 320.518,184.493C317.951,177.998 322.492,179.413 329.46,179.96C371.857,183.285 383.697,217.424 396.841,238.199C402.049,246.431 404.417,195.845 416.933,165.678C466.389,46.47 568.273,63.725 620.454,57.198C644.542,54.186 661.914,53.574 682.917,34.99C689.78,28.917 685.167,52.432 678.1,66.3C632.194,156.379 542.043,161.88 518.51,167.547C494.84,173.247 449.898,171.738 437.246,213.424C429.752,238.116 431.337,273.678 433.497,273.651C437.088,273.605 446.762,238.734 490.466,224.402C502.272,220.53 526.095,220.521 527.076,222.636C527.472,223.49 528.529,257.279 517.05,279.264C493.703,323.977 438.229,298.977 441.171,308.573C443.249,315.353 444.075,314.97 472.98,391.319C479.452,408.415 479.165,408.628 480.43,409.571Z" style="fill:rgb(33,16,2);"/>
|
|
10
|
+
</g>
|
|
11
|
+
</g>
|
|
12
|
+
</svg>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/proofsheet/browser.rb
CHANGED
|
@@ -84,6 +84,17 @@ module Proofsheet
|
|
|
84
84
|
@session.driver.browser.screenshot_as(:png)
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
def image_url_for(selector)
|
|
88
|
+
node = @session.find(selector, match: :first)
|
|
89
|
+
tag_name = node.tag_name.downcase
|
|
90
|
+
raise Error, "#{selector.inspect} selected <#{tag_name}>, expected <img>" unless tag_name == "img"
|
|
91
|
+
|
|
92
|
+
url = @session.evaluate_script("arguments[0].currentSrc || arguments[0].src", node)
|
|
93
|
+
raise Error, "#{selector.inspect} selected an image without a source" if url.nil? || url.empty?
|
|
94
|
+
|
|
95
|
+
url
|
|
96
|
+
end
|
|
97
|
+
|
|
87
98
|
def rect_for(selector, margin: 0)
|
|
88
99
|
node = @session.find(selector, match: :first)
|
|
89
100
|
@session.execute_script(SCROLL_INTO_VIEW, node, margin)
|
data/lib/proofsheet/capturer.rb
CHANGED
|
@@ -5,28 +5,59 @@ require "pathname"
|
|
|
5
5
|
|
|
6
6
|
module Proofsheet
|
|
7
7
|
class Capturer
|
|
8
|
-
def initialize(manifest:, host:, root: Dir.pwd, credentials: nil,
|
|
8
|
+
def initialize(manifest:, host:, root: Dir.pwd, credentials: nil, out: $stdout, **collaborators)
|
|
9
9
|
@manifest = manifest
|
|
10
10
|
@host = host
|
|
11
11
|
@root = Pathname(root)
|
|
12
12
|
@credentials = credentials
|
|
13
|
-
@browser_class = browser_class
|
|
14
13
|
@out = out
|
|
14
|
+
@browser_class = collaborators.fetch(:browser_class, Browser)
|
|
15
|
+
@fetcher = collaborators.fetch(:fetcher, Download)
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
def capture(names = @manifest.names)
|
|
18
|
-
shots = names
|
|
18
|
+
def capture(names = @manifest.names + @manifest.image_names)
|
|
19
|
+
shots, images = split(names)
|
|
19
20
|
username, password = authentication
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
shots.each { |shot| capture_shot(shot) }
|
|
22
|
+
images.select(&:url).each { |image| download(image) }
|
|
23
|
+
browse(shots, images.select(&:page), username, password)
|
|
24
24
|
ensure
|
|
25
25
|
@browser&.quit
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
private
|
|
29
29
|
|
|
30
|
+
def split(names)
|
|
31
|
+
images, shots = names.partition { |name| @manifest.image_names.include?(name) }
|
|
32
|
+
[shots.map { |name| @manifest.shot(name) }, images.map { |name| @manifest.image(name) }]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def browse(shots, pages, username, password)
|
|
36
|
+
return if shots.empty? && pages.empty?
|
|
37
|
+
|
|
38
|
+
@browser = @browser_class.new(host: @host, viewport: @manifest.viewport).start
|
|
39
|
+
sign_in(username, password) if @manifest.login
|
|
40
|
+
shots.each { |shot| capture_shot(shot) }
|
|
41
|
+
pages.each { |image| download_page_image(image) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def download(image, url = image.url)
|
|
45
|
+
@out.puts image.name
|
|
46
|
+
write(image, downloaded_png(image, url))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def download_page_image(image)
|
|
50
|
+
@browser.visit(image.page)
|
|
51
|
+
download(image, @browser.image_url_for(image.selector))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def downloaded_png(image, url)
|
|
55
|
+
require "vips"
|
|
56
|
+
Vips::Image.new_from_buffer(@fetcher.call(url), "").write_to_buffer(".png")
|
|
57
|
+
rescue Vips::Error => e
|
|
58
|
+
raise Error, "#{image.name}: downloaded data is not a supported image: #{e.message}"
|
|
59
|
+
end
|
|
60
|
+
|
|
30
61
|
def authentication
|
|
31
62
|
return [nil, nil] unless @manifest.login
|
|
32
63
|
|
data/lib/proofsheet/cli.rb
CHANGED
|
@@ -63,12 +63,18 @@ module Proofsheet
|
|
|
63
63
|
credentials = Credentials.new(manifest.credentials) if manifest.login
|
|
64
64
|
capturer = @capturer_class.new(manifest: manifest, host: host, root: @root,
|
|
65
65
|
credentials: credentials, out: @out)
|
|
66
|
-
names =
|
|
66
|
+
names = capture_names(manifest)
|
|
67
67
|
@out.puts "Capturing #{names.size} #{names.size == 1 ? "shot" : "shots"} from #{host}"
|
|
68
68
|
capturer.capture(names)
|
|
69
69
|
@out.puts "Done."
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
+
def capture_names(manifest)
|
|
73
|
+
return @argv unless @argv.empty?
|
|
74
|
+
|
|
75
|
+
manifest.names + manifest.image_names
|
|
76
|
+
end
|
|
77
|
+
|
|
72
78
|
def compose(manifest)
|
|
73
79
|
names = @argv.empty? ? manifest.composition_names : @argv
|
|
74
80
|
@out.puts "Composing #{names.size} #{names.size == 1 ? "image" : "images"}"
|
data/lib/proofsheet/composer.rb
CHANGED
|
@@ -41,7 +41,7 @@ module Proofsheet
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def layer_image(layer)
|
|
44
|
-
image = load_image(
|
|
44
|
+
image = load_image(@root.join(@manifest.layer_path(layer)))
|
|
45
45
|
image = Cropper.call(image, layer.crop) if layer.crop
|
|
46
46
|
image = image.resize(layer.width.to_f / image.width) if layer.width
|
|
47
47
|
image = RoundedCorners.call(image, layer.radius)
|
|
@@ -5,7 +5,7 @@ module Proofsheet
|
|
|
5
5
|
Background = Data.define(:color, :gradient, :image, :angle)
|
|
6
6
|
Shadow = Data.define(:x, :y, :blur, :color)
|
|
7
7
|
Crop = Data.define(:x, :y, :width, :height)
|
|
8
|
-
Layer = Data.define(:shot, :x, :y, :crop, :width, :radius, :rotate, :shadow)
|
|
8
|
+
Layer = Data.define(:shot, :image, :x, :y, :crop, :width, :radius, :rotate, :shadow)
|
|
9
9
|
Composition = Data.define(:name, :width, :height, :background, :layers) do
|
|
10
10
|
def filename
|
|
11
11
|
"#{name}.png"
|
|
@@ -28,7 +28,7 @@ module Proofsheet
|
|
|
28
28
|
width, height = raw.fetch("canvas")
|
|
29
29
|
Composition.new(name: name, width: width, height: height,
|
|
30
30
|
background: background(raw.fetch("background", "#ffffff")),
|
|
31
|
-
layers: raw.fetch("layers").map { |layer| layer_spec(layer) })
|
|
31
|
+
layers: raw.fetch("layers").map { |layer| layer_spec(layer, name) })
|
|
32
32
|
rescue KeyError => e
|
|
33
33
|
raise Error, "#{name}: #{e.message} in #{@path}"
|
|
34
34
|
end
|
|
@@ -46,8 +46,11 @@ module Proofsheet
|
|
|
46
46
|
angle: raw.fetch("angle", 0))
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def layer_spec(raw)
|
|
50
|
-
|
|
49
|
+
def layer_spec(raw, name)
|
|
50
|
+
source = [raw["shot"], raw["image"]].compact
|
|
51
|
+
raise Error, "#{name}: a layer must set exactly one of shot or image" unless source.one?
|
|
52
|
+
|
|
53
|
+
Layer.new(shot: raw["shot"], image: raw["image"], x: raw.fetch("x", 0), y: raw.fetch("y", 0),
|
|
51
54
|
crop: crop(raw["crop"]), width: raw["width"], radius: raw.fetch("radius", 0),
|
|
52
55
|
rotate: raw.fetch("rotate", 0), shadow: shadow(raw["shadow"]))
|
|
53
56
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open-uri"
|
|
4
|
+
require "socket"
|
|
5
|
+
|
|
6
|
+
module Proofsheet
|
|
7
|
+
class Download
|
|
8
|
+
FAILURES = [URI::InvalidURIError, OpenURI::HTTPError, RuntimeError, SystemCallError, SocketError].freeze
|
|
9
|
+
|
|
10
|
+
def self.call(url)
|
|
11
|
+
new(url).call
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(url)
|
|
15
|
+
@url = url.to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def call
|
|
19
|
+
uri = URI.parse(@url)
|
|
20
|
+
raise Error, "#{@url.inspect} is not an http or https URL" unless uri.is_a?(URI::HTTP)
|
|
21
|
+
|
|
22
|
+
uri.read
|
|
23
|
+
rescue *FAILURES => e
|
|
24
|
+
raise Error, "could not fetch #{@url}: #{e.message}"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Proofsheet
|
|
4
|
+
class ImageConfig
|
|
5
|
+
SOURCES = %w[path url page].freeze
|
|
6
|
+
|
|
7
|
+
Image = Data.define(:name, :path, :url, :page, :selector) do
|
|
8
|
+
def filename = "#{name}.png"
|
|
9
|
+
def local? = !path.nil?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(data, path:)
|
|
13
|
+
@data = data
|
|
14
|
+
@path = path
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def names
|
|
18
|
+
@data.keys
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def fetch(name)
|
|
22
|
+
raw = @data[name]
|
|
23
|
+
raise Error, "unknown image #{name.inspect} — known images: #{names.join(", ")}" if raw.nil?
|
|
24
|
+
|
|
25
|
+
sources = SOURCES.select { |key| raw[key] }
|
|
26
|
+
raise Error, "#{name}: set exactly one of path, url, or page in #{@path}" unless sources.one?
|
|
27
|
+
|
|
28
|
+
validate_selector(name, raw)
|
|
29
|
+
|
|
30
|
+
Image.new(name: name, path: raw["path"], url: raw["url"], page: raw["page"],
|
|
31
|
+
selector: raw["selector"])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def validate_selector(name, raw)
|
|
37
|
+
raise Error, "#{name}: page requires selector in #{@path}" if raw["page"] && !raw["selector"]
|
|
38
|
+
return unless raw["selector"] && !raw["page"]
|
|
39
|
+
|
|
40
|
+
raise Error, "#{name}: selector can only be used with page in #{@path}"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/proofsheet/manifest.rb
CHANGED
|
@@ -73,6 +73,17 @@ module Proofsheet
|
|
|
73
73
|
names.map { |name| shot(name) }
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
def image_names = image_config.names
|
|
77
|
+
|
|
78
|
+
def image(name) = image_config.fetch(name)
|
|
79
|
+
|
|
80
|
+
def layer_path(layer)
|
|
81
|
+
return File.join(output_dir, "#{layer.shot}.png") if layer.shot
|
|
82
|
+
|
|
83
|
+
source = image(layer.image)
|
|
84
|
+
source.local? ? source.path : File.join(output_dir, source.filename)
|
|
85
|
+
end
|
|
86
|
+
|
|
76
87
|
def composition_names = composition_config.names
|
|
77
88
|
|
|
78
89
|
def composition(name)
|
|
@@ -131,6 +142,19 @@ module Proofsheet
|
|
|
131
142
|
raise Error, "shots is missing from #{@path}"
|
|
132
143
|
end
|
|
133
144
|
|
|
145
|
+
def image_config
|
|
146
|
+
@image_config ||= ImageConfig.new(@data.fetch("images", {}), path: @path).tap do |config|
|
|
147
|
+
reject_clashes(config.names)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def reject_clashes(names)
|
|
152
|
+
clashes = names & shot_data.keys
|
|
153
|
+
return if clashes.empty?
|
|
154
|
+
|
|
155
|
+
raise Error, "#{clashes.join(", ")} named as both a shot and an image in #{@path}"
|
|
156
|
+
end
|
|
157
|
+
|
|
134
158
|
def composition_config
|
|
135
159
|
@composition_config ||= CompositionConfig.new(@data.fetch("compositions", {}), path: @path)
|
|
136
160
|
end
|
data/lib/proofsheet/version.rb
CHANGED
data/lib/proofsheet.rb
CHANGED
|
@@ -10,7 +10,9 @@ end
|
|
|
10
10
|
require_relative "proofsheet/browser"
|
|
11
11
|
require_relative "proofsheet/clip"
|
|
12
12
|
require_relative "proofsheet/credentials"
|
|
13
|
+
require_relative "proofsheet/download"
|
|
13
14
|
require_relative "proofsheet/composition_config"
|
|
15
|
+
require_relative "proofsheet/image_config"
|
|
14
16
|
require_relative "proofsheet/manifest"
|
|
15
17
|
require_relative "proofsheet/capturer"
|
|
16
18
|
require_relative "proofsheet/cropper"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: proofsheet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marc Heiligers
|
|
@@ -64,6 +64,24 @@ files:
|
|
|
64
64
|
- LICENSE.txt
|
|
65
65
|
- README.md
|
|
66
66
|
- Rakefile
|
|
67
|
+
- USAGE.md
|
|
68
|
+
- examples/01_simple.yml
|
|
69
|
+
- examples/02_targets_and_clipping.yml
|
|
70
|
+
- examples/03_authentication.yml
|
|
71
|
+
- examples/04_fetching_images.yml
|
|
72
|
+
- examples/05_compositions.yml
|
|
73
|
+
- examples/assets/logo.svg
|
|
74
|
+
- examples/assets/logo480.png
|
|
75
|
+
- examples/assets/wordmark_960_104.png
|
|
76
|
+
- examples/output/avo_dashboard.png
|
|
77
|
+
- examples/output/cat_badge.png
|
|
78
|
+
- examples/output/cat_placeholder.png
|
|
79
|
+
- examples/output/contact_sheet_lead.png
|
|
80
|
+
- examples/output/fascination_logo.png
|
|
81
|
+
- examples/output/homepage.png
|
|
82
|
+
- examples/output/sample_page.png
|
|
83
|
+
- examples/output/showcase.png
|
|
84
|
+
- examples/output/web_page.png
|
|
67
85
|
- exe/proofsheet
|
|
68
86
|
- lib/proofsheet.rb
|
|
69
87
|
- lib/proofsheet/browser.rb
|
|
@@ -74,6 +92,8 @@ files:
|
|
|
74
92
|
- lib/proofsheet/composition_config.rb
|
|
75
93
|
- lib/proofsheet/credentials.rb
|
|
76
94
|
- lib/proofsheet/cropper.rb
|
|
95
|
+
- lib/proofsheet/download.rb
|
|
96
|
+
- lib/proofsheet/image_config.rb
|
|
77
97
|
- lib/proofsheet/manifest.rb
|
|
78
98
|
- lib/proofsheet/rounded_corners.rb
|
|
79
99
|
- lib/proofsheet/version.rb
|
|
@@ -100,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
100
120
|
- !ruby/object:Gem::Version
|
|
101
121
|
version: '0'
|
|
102
122
|
requirements: []
|
|
103
|
-
rubygems_version: 4.0.
|
|
123
|
+
rubygems_version: 4.0.20
|
|
104
124
|
specification_version: 4
|
|
105
125
|
summary: Capture repeatable screenshots from web applications
|
|
106
126
|
test_files: []
|