himg 0.0.4 → 0.0.6
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 +23 -0
- data/Cargo.lock +548 -1047
- data/LICENSE-APACHE.txt +203 -0
- data/README.md +93 -39
- data/ext/himg/Cargo.toml +10 -7
- data/ext/himg/examples/assets/github_profile_offline.html +86 -0
- data/ext/himg/examples/file.rs +9 -8
- data/ext/himg/src/html_to_image.rs +34 -36
- data/ext/himg/src/image_size.rs +1 -1
- data/ext/himg/src/lib.rs +19 -15
- data/ext/himg/src/net_fetcher.rs +139 -0
- data/ext/himg/src/options.rs +22 -3
- data/ext/himg/src/renderer.rs +7 -5
- data/gemfiles/plain_ruby.gemfile.lock +1 -1
- data/gemfiles/rails_6.gemfile.lock +1 -1
- data/gemfiles/rails_7_0.gemfile.lock +1 -1
- data/gemfiles/rails_7_1.gemfile.lock +1 -1
- data/gemfiles/rails_7_2.gemfile.lock +1 -1
- data/gemfiles/rails_8.gemfile.lock +1 -1
- data/lib/himg/base_url.rb +21 -0
- data/lib/himg/cli.rb +64 -0
- data/lib/himg/railtie/controller_config.rb +31 -0
- data/lib/himg/railtie/template_handler.rb +2 -2
- data/lib/himg/railtie.rb +13 -2
- data/lib/himg/version.rb +1 -1
- data/lib/himg.rb +4 -2
- data/readme_hero.svg +54 -0
- data/sig/himg.rbs +11 -3
- metadata +9 -2
- /data/{LICENSE.txt → LICENSE-MIT.txt} +0 -0
data/LICENSE-APACHE.txt
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
203
|
+
|
data/README.md
CHANGED
@@ -2,46 +2,29 @@
|
|
2
2
|
|
3
3
|
You give it HTML and it gives back an image!
|
4
4
|
|
5
|
-
Parses a minimal subset of HTML/CSS, fetches nested resources, renders an image on the GPU.
|
5
|
+
Parses a minimal subset of HTML/CSS, fetches nested resources, renders an image on the GPU. No browser, no fuss.
|
6
6
|
|
7
|
-
|
7
|
+

|
8
8
|
|
9
|
-
|
9
|
+
## Quickstart
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
1. This is **pre-alpha** software, don't expect it to work yet.
|
14
|
-
2. Rendering requires a GPU. Awaiting CPU support in vello, which Canva may be working on.
|
15
|
-
3. Performance needs tuning. Both in the underlying blitz library and how data is passed between Rust and Ruby
|
16
|
-
4. Network requests can be made: don't use this library with untrusted inputs.
|
17
|
-
5. file:// URLs are resolved: this could expose files on your computer.
|
18
|
-
6. Native extensions are not yet being published for different os/arch
|
19
|
-
7. Verbose logging is hardcoded
|
20
|
-
|
21
|
-
## Installation
|
22
|
-
|
23
|
-
Install the gem and add to the application's Gemfile by executing:
|
24
|
-
|
25
|
-
```bash
|
26
|
-
bundle add himg
|
27
|
-
```
|
28
|
-
|
29
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
11
|
+
### Command Line
|
30
12
|
|
31
13
|
```bash
|
32
|
-
|
14
|
+
bin/himg screenshot path/to/your.html screenshot.png
|
15
|
+
bin/himg screenshot https://github.com/Jamedjo/himg himg.png --width=1024 --verbose --no-truncate
|
33
16
|
```
|
34
17
|
|
35
|
-
## Usage
|
36
|
-
|
37
18
|
### Ruby
|
38
19
|
|
39
20
|
```ruby
|
40
|
-
png = Himg.render("
|
21
|
+
png = Himg.render("<!DOCTYPE html><body style='background:blue;'></body>")
|
22
|
+
File.open("blue.png", "wb"){|f| f.write(png) }
|
41
23
|
```
|
42
24
|
|
43
25
|
```ruby
|
44
|
-
png = Himg.render("
|
26
|
+
png = Himg.render("<!DOCTYPE html><h1>Snapshot</h1>", width: 89, height: 5, truncate: false)
|
27
|
+
File.open("dynamic_height.png", "wb"){|f| f.write(png) }
|
45
28
|
```
|
46
29
|
|
47
30
|
### Rails
|
@@ -52,9 +35,9 @@ Simply add a `show.himg.erb`!
|
|
52
35
|
<div><%= @username %></div>
|
53
36
|
```
|
54
37
|
|
55
|
-
###
|
38
|
+
### OpenGraph Meta Tags
|
56
39
|
|
57
|
-
|
40
|
+
OpenGraph tags let messenger apps and social media sites know to use your generated image as a thumbnail card for your website.
|
58
41
|
|
59
42
|
```html
|
60
43
|
<meta property="og:title" content="<%= @user.username %>" />
|
@@ -62,13 +45,62 @@ Once you've added a view template for your resource, you can use it to generate
|
|
62
45
|
<meta property="og:image" content="<%= user_url(@user.username, format: :png) %>" />
|
63
46
|
```
|
64
47
|
|
65
|
-
|
48
|
+
# Usage
|
49
|
+
|
50
|
+
Install the gem and add to the application's Gemfile by executing:
|
51
|
+
|
52
|
+
```bash
|
53
|
+
bundle add himg
|
54
|
+
```
|
55
|
+
|
56
|
+
## Configuration
|
57
|
+
|
58
|
+
|Option | Description | Type | Default |
|
59
|
+
|-|-|-|-|
|
60
|
+
|width | Sets the width of the rendered content. | integer | 720 |
|
61
|
+
|height | Sets the desired height of the rendered output. | integer | 405 |
|
62
|
+
|truncate | Keeps the image height fixed instead of expanding to include the full page | bool | true |
|
63
|
+
|verbose | Enables detailed logging for debugging and profiling. | bool | false |
|
64
|
+
|base_url | Where relative paths are relative to for linked resources (stylesheets, images, fonts, etc) | string | nil |
|
65
|
+
|disable_fetch | Disables fetching linked resources from disk and network| bool | false |
|
66
|
+
|
66
67
|
|
67
|
-
|
68
|
+
### Passing options to a Rails view template
|
69
|
+
|
70
|
+
Options can be set at a controller level using the `himg_config` helper method:
|
71
|
+
```ruby
|
72
|
+
class UsersController < ActionController::Base
|
73
|
+
himg_config(verbose: true)
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
These can be overridden at a view level:
|
78
|
+
```ruby
|
79
|
+
class UsersController < ActionController::Base
|
80
|
+
def show
|
81
|
+
himg_config(width: params[:w]) if params[:w]
|
82
|
+
|
83
|
+
@user = User.new
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
### Rails manual render
|
68
88
|
|
69
89
|
If you prefer you could also use `render himg: "<div>My Data</div>"` instead, but should be careful with untrusted input if constructing HTML manually.
|
70
90
|
|
71
|
-
|
91
|
+
Options can then be passed directly to the manual render:
|
92
|
+
```ruby
|
93
|
+
render himg: '<!DOCTYPE html>', truncate: false
|
94
|
+
```
|
95
|
+
|
96
|
+
Alternatively you can pass in options which have been set with `himg_config`:
|
97
|
+
```ruby
|
98
|
+
render himg: '<!DOCTYPE html>', config: himg_config
|
99
|
+
```
|
100
|
+
|
101
|
+
### Rails `respond_to`
|
102
|
+
|
103
|
+
To be explicit in the controller you can also use `respond_to` style:
|
72
104
|
|
73
105
|
```ruby
|
74
106
|
respond_to do |format|
|
@@ -77,6 +109,7 @@ respond_to do |format|
|
|
77
109
|
end
|
78
110
|
```
|
79
111
|
|
112
|
+
You can also use this combined with a manual render:
|
80
113
|
```ruby
|
81
114
|
respond_to do |format|
|
82
115
|
format.html
|
@@ -85,14 +118,25 @@ respond_to do |format|
|
|
85
118
|
end
|
86
119
|
```
|
87
120
|
|
88
|
-
|
121
|
+
# How it works
|
89
122
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
```
|
123
|
+
No browser, just basics!
|
124
|
+
|
125
|
+
Himg calls through to the amazing blitz library, which uses Stylo to parse the CSS, servo/html5ever to parse the HTML, fetches network resources, builds a scene graph and hands over to vello to render an image.
|
94
126
|
|
95
|
-
|
127
|
+
Interaction between Ruby & Rust is done with the help of `magnus`, `rb_sys` and lots of glue code from the `oxidize-rb` team.
|
128
|
+
|
129
|
+
To play nicely with Rails a template handler is registered, which Rails' `default_render` method automatically calls when the corresponding view is found. This can be `show.himg` for a static image, or `show.himg.erb` to use variables from the controller. Additionally a Renderer is available with `render himg: 'content'` in case a view template is not needed.
|
130
|
+
|
131
|
+
## CAVEATS
|
132
|
+
|
133
|
+
1. This is **pre-alpha** software, don't expect it to work yet.
|
134
|
+
2. Performance needs tuning. Both in the underlying blitz library and how data is passed between Rust and Ruby
|
135
|
+
3. Network requests can be made: don't use this library with untrusted inputs. Use `disable_fetch` if you don't need to fetch any resources.
|
136
|
+
4. file:// URLs are resolved: this could expose files on your computer. Use `disable_fetch` if you don't need to fetch any resources.
|
137
|
+
5. Native extensions are not yet being published for different os/arch
|
138
|
+
|
139
|
+
# Development
|
96
140
|
|
97
141
|
1. Run `bin/setup` to install dependencies.
|
98
142
|
2. Run `rake spec` to run the tests with the default development setup
|
@@ -104,6 +148,12 @@ bundle exec cargo run --example file -- path/to/file.html
|
|
104
148
|
- http://localhost:3000/users/jamedjo will render an HTML page with opengraph meta tags
|
105
149
|
6. To install this gem onto your local machine, run `bundle exec rake install`.
|
106
150
|
|
151
|
+
### Run cargo example directly generate image in Rust
|
152
|
+
|
153
|
+
```bash
|
154
|
+
bundle exec cargo run --example file
|
155
|
+
bundle exec cargo run --example file -- path/to/file.html
|
156
|
+
```
|
107
157
|
## Releases
|
108
158
|
|
109
159
|
To release a new version:
|
@@ -116,4 +166,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jamedj
|
|
116
166
|
|
117
167
|
## License
|
118
168
|
|
119
|
-
|
169
|
+
Copyright (c) 2025 James Edwards-Jones
|
170
|
+
|
171
|
+
This project is dual licenced under both the MIT and Apache 2.0 terms.
|
172
|
+
|
173
|
+
See: [MIT License](https://opensource.org/licenses/MIT) and [APACHE 2.0 License](http://www.apache.org/licenses/LICENSE-2.0)
|
data/ext/himg/Cargo.toml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[package]
|
2
2
|
name = "himg"
|
3
3
|
description = "ruby bindings to expose a blitz html->png pipeline"
|
4
|
-
version = "0.0.
|
4
|
+
version = "0.0.6"
|
5
5
|
edition = "2024"
|
6
6
|
authors = ["James Edwards-Jones <git@jamedjo.co.uk>"]
|
7
7
|
license = "MIT"
|
@@ -14,13 +14,16 @@ crate-type = ["cdylib", "rlib"]
|
|
14
14
|
[dependencies]
|
15
15
|
magnus = { version = "0.7.1" }
|
16
16
|
rb-sys = { version = "0.9", features = ["stable-api-compiled-fallback"] }
|
17
|
-
blitz-traits = { version = "0.1.0-
|
18
|
-
blitz-dom = { version = "0.1.0-
|
19
|
-
blitz-net = { version = "0.1.0-
|
20
|
-
blitz-
|
21
|
-
|
22
|
-
|
17
|
+
blitz-traits = { version = "0.1.0-rc.1" }
|
18
|
+
blitz-dom = { version = "0.1.0-rc.1" }
|
19
|
+
blitz-net = { version = "0.1.0-rc.1" }
|
20
|
+
blitz-paint = { version = "0.1.0-rc.1" }
|
21
|
+
anyrender = { version = "0.5.0" }
|
22
|
+
anyrender_vello_cpu = { version = "0.5.0" }
|
23
|
+
blitz-html = { version = "0.1.0-rc.1" }
|
24
|
+
tokio = { version = "1.46", features = ["rt-multi-thread", "macros"] }
|
23
25
|
png = "0.17"
|
26
|
+
openssl = { version = "0.10", features = ["vendored"] }
|
24
27
|
|
25
28
|
#euclid = { workspace = true }
|
26
29
|
#image = { workspace = true }
|
@@ -0,0 +1,86 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head><style type="text/css">.turbo-progress-bar {
|
4
|
+
position: fixed;
|
5
|
+
display: block;
|
6
|
+
top: 0;
|
7
|
+
left: 0;
|
8
|
+
height: 3px;
|
9
|
+
background: #0076ff;
|
10
|
+
z-index: 2147483647;
|
11
|
+
transition:
|
12
|
+
width 300ms ease-out,
|
13
|
+
opacity 150ms 150ms ease-in;
|
14
|
+
transform: translate3d(0, 0, 0);
|
15
|
+
}
|
16
|
+
</style>
|
17
|
+
<meta charset="utf-8">
|
18
|
+
<title>nicoburns (Nico Burns)</title>
|
19
|
+
|
20
|
+
<meta name="viewport" content="width=device-width">
|
21
|
+
<meta name="description" content="nicoburns has 79 repositories available. Follow their code on GitHub.">
|
22
|
+
<meta name="hostname" content="github.com">
|
23
|
+
<meta name="expected-hostname" content="github.com">
|
24
|
+
<meta name="theme-color" content="#1e2327">
|
25
|
+
<meta name="color-scheme" content="light dark">
|
26
|
+
</head>
|
27
|
+
<body>
|
28
|
+
<div class="Box d-flex p-3 width-full public source">
|
29
|
+
<div class="pinned-item-list-item-content">
|
30
|
+
<div class="d-flex width-full position-relative">
|
31
|
+
<div class="flex-1">
|
32
|
+
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo mr-1 color-fg-muted">
|
33
|
+
<path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path>
|
34
|
+
</svg>
|
35
|
+
<span data-view-component="true" class="position-relative"><a data-hydro-click="{"event_type":"user_profile.click","payload":{"profile_user_id":1007307,"target":"PINNED_REPO","user_id":1007307,"originating_url":"https://github.com/nicoburns"}}" data-hydro-click-hmac="95bab3b0debdfa7d41ff86f71264a58e15a16e2c317afd1444c387724a44f62d" id="464340188" href="/DioxusLabs/blitz" data-view-component="true" class="Link mr-1 text-bold wb-break-word" aria-labelledby="tooltip-7d61525f-6eaa-4bf0-a1c6-b8ec7d17b15b"><span class="owner text-normal">DioxusLabs/</span><span class="repo">blitz</span></a> <tool-tip id="tooltip-7d61525f-6eaa-4bf0-a1c6-b8ec7d17b15b" for="464340188" popover="manual" data-direction="s" data-type="label" data-view-component="true" class="position-absolute sr-only" aria-hidden="true" role="tooltip" style="--tool-tip-position-top: 1239.265625px; --tool-tip-position-left: 500.75390625px;">DioxusLabs/blitz</tool-tip></span> <span></span><span class="Label Label--secondary v-align-middle mt-1 no-wrap v-align-baseline Label--inline">Public</span>
|
36
|
+
</div>
|
37
|
+
<div>
|
38
|
+
<input type="hidden" name="pinned_items_id_and_type[]" id="pinned-item-reorder-464340188" value="464340188-Repository" autocomplete="off" class="form-control">
|
39
|
+
<span role="button" class="pinned-item-handle js-pinned-item-reorder" aria-label="Drag to reorder">
|
40
|
+
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-grabber">
|
41
|
+
<path d="M10 13a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm0-4a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm-4 4a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm5-9a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM7 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM6 5a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path>
|
42
|
+
</svg>
|
43
|
+
</span>
|
44
|
+
<button data-direction="up" type="button" data-view-component="true" class="show-on-focus sortable-button js-sortable-button Button--secondary Button--small Button right-0"> <span class="Button-content">
|
45
|
+
<span class="Button-label"><svg aria-label="Move blitz up" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-chevron-up">
|
46
|
+
<path d="M3.22 10.53a.749.749 0 0 1 0-1.06l4.25-4.25a.749.749 0 0 1 1.06 0l4.25 4.25a.749.749 0 1 1-1.06 1.06L8 6.811 4.28 10.53a.749.749 0 0 1-1.06 0Z"></path>
|
47
|
+
</svg></span>
|
48
|
+
</span>
|
49
|
+
</button>
|
50
|
+
<button data-direction="down" type="button" data-view-component="true" class="show-on-focus sortable-button js-sortable-button Button--secondary Button--small Button right-0"> <span class="Button-content">
|
51
|
+
<span class="Button-label"><svg aria-label="Move blitz down" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-chevron-down">
|
52
|
+
<path d="M12.78 5.22a.749.749 0 0 1 0 1.06l-4.25 4.25a.749.749 0 0 1-1.06 0L3.22 6.28a.749.749 0 1 1 1.06-1.06L8 8.939l3.72-3.719a.749.749 0 0 1 1.06 0Z"></path>
|
53
|
+
</svg></span>
|
54
|
+
</span>
|
55
|
+
</button>
|
56
|
+
</div>
|
57
|
+
</div>
|
58
|
+
|
59
|
+
|
60
|
+
<p class="pinned-item-desc color-fg-muted text-small mt-2 mb-0">
|
61
|
+
A radically modular HTML/CSS rendering engine
|
62
|
+
</p>
|
63
|
+
|
64
|
+
<p class="mb-0 mt-2 f6 color-fg-muted">
|
65
|
+
<span class="d-inline-block mr-3">
|
66
|
+
<span class="repo-language-color" style="background-color: #dea584"></span>
|
67
|
+
<span itemprop="programmingLanguage">Rust</span>
|
68
|
+
</span>
|
69
|
+
|
70
|
+
<a href="/DioxusLabs/blitz/stargazers" class="pinned-item-meta Link--muted">
|
71
|
+
<svg aria-label="stars" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-star">
|
72
|
+
<path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"></path>
|
73
|
+
</svg>
|
74
|
+
2.2k
|
75
|
+
</a>
|
76
|
+
<a href="/DioxusLabs/blitz/forks" class="pinned-item-meta Link--muted">
|
77
|
+
<svg aria-label="forks" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo-forked">
|
78
|
+
<path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"></path>
|
79
|
+
</svg>
|
80
|
+
50
|
81
|
+
</a>
|
82
|
+
</p>
|
83
|
+
</div>
|
84
|
+
</div>
|
85
|
+
</body>
|
86
|
+
</html>
|
data/ext/himg/examples/file.rs
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
use himg::{html_to_image, Options, ImageSize, write_png};
|
4
4
|
use himg::logger::{Logger, TimedLogger};
|
5
5
|
|
6
|
-
use blitz_traits::{ColorScheme};
|
6
|
+
use blitz_traits::shell::{ColorScheme};
|
7
7
|
use std::{
|
8
8
|
fs::File,
|
9
9
|
path::{Path, PathBuf},
|
@@ -14,14 +14,14 @@ async fn main() {
|
|
14
14
|
let mut logger = TimedLogger::init();
|
15
15
|
|
16
16
|
let path_string = std::env::args()
|
17
|
-
.
|
18
|
-
.next()
|
17
|
+
.nth(1)
|
19
18
|
.unwrap_or_else(|| "./ext/himg/examples/assets/github_profile.html".into());
|
20
19
|
println!("Loading {}", path_string);
|
20
|
+
let base_url = format!("file://{}", path_string.clone());
|
21
21
|
|
22
22
|
// Fetch HTML from path
|
23
23
|
let html = std::fs::read_to_string(&path_string).unwrap();
|
24
|
-
logger.log("
|
24
|
+
logger.log("Read HTML");
|
25
25
|
|
26
26
|
// Configure viewport dimensions
|
27
27
|
let options = Options {
|
@@ -31,20 +31,21 @@ async fn main() {
|
|
31
31
|
hidpi_scale: 1.0,
|
32
32
|
},
|
33
33
|
truncate: false,
|
34
|
+
verbose: true,
|
34
35
|
color_scheme: ColorScheme::Light,
|
35
|
-
|
36
|
+
disable_fetch: false,
|
37
|
+
base_url: Some(base_url),
|
36
38
|
};
|
37
39
|
|
38
40
|
// Render to Image
|
39
|
-
let
|
40
|
-
let buffer = html_to_image(&html, Some(base_url), options, &mut logger).await;
|
41
|
+
let render_output = html_to_image(&html, options, &mut logger).await;
|
41
42
|
|
42
43
|
// Determine output path, and open a file at that path.
|
43
44
|
let out_path = compute_filename(&path_string);
|
44
45
|
let mut file = File::create(&out_path).unwrap();
|
45
46
|
|
46
47
|
// Encode buffer as PNG and write it to a file
|
47
|
-
write_png(&mut file, &buffer,
|
48
|
+
write_png(&mut file, &render_output.buffer, render_output.image_size.scaled_width(), render_output.image_size.scaled_height()).unwrap();
|
48
49
|
logger.log("Wrote out png");
|
49
50
|
|
50
51
|
logger.log_total_time("\nDone");
|