himg 0.0.5 → 0.0.7

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.
@@ -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,37 +2,21 @@
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. No browser, no fuss.
6
6
 
7
- Uses rust libraries to do this in a fast, hopefully safe way.
7
+ Perfect for OpenGraph images - stop losing clicks to boring links by adding a rich image preview that showcases your content.
8
8
 
9
- In Rails this will mean you can process user.himg.erb to display an image including data from a user's profile.
9
+ ![Mockup showing HTML being transformed into a WhatsApp preview](/readme_hero.svg)
10
10
 
11
- ## CAVEATS
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
11
+ ## Quickstart
19
12
 
20
- ## Installation
21
-
22
- Install the gem and add to the application's Gemfile by executing:
13
+ ### Command Line
23
14
 
24
15
  ```bash
25
- bundle add himg
16
+ himg screenshot path/to/your.html screenshot.png
17
+ himg screenshot https://github.com/Jamedjo/himg himg.png --width=1024 --verbose --no-truncate
26
18
  ```
27
19
 
28
- If bundler is not being used to manage dependencies, install the gem by executing:
29
-
30
- ```bash
31
- gem install himg
32
- ```
33
-
34
- ## Usage
35
-
36
20
  ### Ruby
37
21
 
38
22
  ```ruby
@@ -53,9 +37,9 @@ Simply add a `show.himg.erb`!
53
37
  <div><%= @username %></div>
54
38
  ```
55
39
 
56
- ### Adding OpenGraph Meta Tags
40
+ ### OpenGraph Meta Tags
57
41
 
58
- Once you've added a view template for your resource, you can use it to generate image cards that will be shown when the page is shared on messenger apps or social media.
42
+ OpenGraph tags let messenger apps and social media sites know to use your generated image as a thumbnail card for your website.
59
43
 
60
44
  ```html
61
45
  <meta property="og:title" content="<%= @user.username %>" />
@@ -63,9 +47,26 @@ Once you've added a view template for your resource, you can use it to generate
63
47
  <meta property="og:image" content="<%= user_url(@user.username, format: :png) %>" />
64
48
  ```
65
49
 
66
- ### Configuration Options
50
+ # Usage
51
+
52
+ Install the gem and add to the application's Gemfile by executing:
53
+
54
+ ```bash
55
+ bundle add himg
56
+ ```
57
+
58
+ ## Configuration
59
+
60
+ |Option | Description | Type | Default |
61
+ |-|-|-|-|
62
+ |width | Sets the width of the rendered content. | integer | 720 |
63
+ |height | Sets the desired height of the rendered output. | integer | 405 |
64
+ |truncate | Keeps the image height fixed instead of expanding to include the full page | bool | true |
65
+ |verbose | Enables detailed logging for debugging and profiling. | bool | false |
66
+ |base_url | Where relative paths are relative to for linked resources (stylesheets, images, fonts, etc) | string | nil |
67
+ |disable_fetch | Disables fetching linked resources from disk and network| bool | false |
68
+ |fetch_timeout | Timeout in seconds for fetching resources | float | 10.0 |
67
69
 
68
- Options: `width`, `height`, `verbose`, `truncate`.
69
70
 
70
71
  ### Passing options to a Rails view template
71
72
 
@@ -120,7 +121,7 @@ respond_to do |format|
120
121
  end
121
122
  ```
122
123
 
123
- ### How it works
124
+ # How it works
124
125
 
125
126
  No browser, just basics!
126
127
 
@@ -130,14 +131,15 @@ Interaction between Ruby & Rust is done with the help of `magnus`, `rb_sys` and
130
131
 
131
132
  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.
132
133
 
133
- ### Run directly from the command line to output an image
134
+ ## CAVEATS
134
135
 
135
- ```bash
136
- bundle exec cargo run --example file
137
- bundle exec cargo run --example file -- path/to/file.html
138
- ```
136
+ 1. This is **pre-alpha** software, don't expect it to work perfectly yet.
137
+ 2. Performance needs tuning. Both in the underlying blitz library and how data is passed between Rust and Ruby
138
+ 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.
139
+ 4. file:// URLs are resolved: this could expose files on your computer. Use `disable_fetch` if you don't need to fetch any resources.
140
+ 5. Native extensions are not yet being published for different os/arch
139
141
 
140
- ## Development
142
+ # Development
141
143
 
142
144
  1. Run `bin/setup` to install dependencies.
143
145
  2. Run `rake spec` to run the tests with the default development setup
@@ -149,6 +151,12 @@ bundle exec cargo run --example file -- path/to/file.html
149
151
  - http://localhost:3000/users/jamedjo will render an HTML page with opengraph meta tags
150
152
  6. To install this gem onto your local machine, run `bundle exec rake install`.
151
153
 
154
+ ### Run cargo example directly generate image in Rust
155
+
156
+ ```bash
157
+ bundle exec cargo run --example file
158
+ bundle exec cargo run --example file -- path/to/file.html
159
+ ```
152
160
  ## Releases
153
161
 
154
162
  To release a new version:
@@ -161,4 +169,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jamedj
161
169
 
162
170
  ## License
163
171
 
164
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
172
+ Copyright (c) 2025 James Edwards-Jones
173
+
174
+ This project is dual licenced under both the MIT and Apache 2.0 terms.
175
+
176
+ See: [MIT License](https://opensource.org/licenses/MIT) and [APACHE 2.0 License](http://www.apache.org/licenses/LICENSE-2.0)
data/exe/himg ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+
5
+ require "himg"
6
+ require "himg/cli"
7
+ Himg::CLI.start(ARGV)
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.5"
4
+ version = "0.0.7"
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-alpha.1" }
18
- blitz-dom = { version = "0.1.0-alpha.1" }
19
- blitz-net = { version = "0.1.0-alpha.1" }
20
- blitz-renderer-vello = { version = "0.1.0-alpha.1" }
21
- blitz-html = { version = "0.1.0-alpha.1" }
22
- tokio = { version = "1.42", features = ["rt-multi-thread", "macros"] }
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="{&quot;event_type&quot;:&quot;user_profile.click&quot;,&quot;payload&quot;:{&quot;profile_user_id&quot;:1007307,&quot;target&quot;:&quot;PINNED_REPO&quot;,&quot;user_id&quot;:1007307,&quot;originating_url&quot;:&quot;https://github.com/nicoburns&quot;}}" 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>
@@ -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,10 +14,10 @@ async fn main() {
14
14
  let mut logger = TimedLogger::init();
15
15
 
16
16
  let path_string = std::env::args()
17
- .skip(1)
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();
@@ -33,12 +33,13 @@ async fn main() {
33
33
  truncate: false,
34
34
  verbose: true,
35
35
  color_scheme: ColorScheme::Light,
36
- allow_net_requests: true, //TODO: Implement using this
36
+ disable_fetch: false,
37
+ fetch_timeout: 10.0,
38
+ base_url: Some(base_url),
37
39
  };
38
40
 
39
41
  // Render to Image
40
- let base_url = format!("file://{}", path_string.clone());
41
- let render_output = html_to_image(&html, Some(base_url), options, &mut logger).await;
42
+ let render_output = html_to_image(&html, options, &mut logger).await;
42
43
 
43
44
  // Determine output path, and open a file at that path.
44
45
  let out_path = compute_filename(&path_string);
@@ -1,15 +1,15 @@
1
- use blitz_dom::net::Resource;
2
1
  use blitz_html::HtmlDocument;
3
- use blitz_net::{MpscCallback, Provider};
4
- use blitz_renderer_vello::render_to_buffer;
5
- use blitz_traits::navigation::DummyNavigationProvider;
6
- use blitz_traits::net::SharedProvider;
7
- use blitz_traits::{ColorScheme, Viewport};
8
- use std::sync::Arc;
2
+ use blitz_dom::DocumentConfig;
3
+ use anyrender_vello_cpu::VelloCpuImageRenderer;
4
+ use anyrender::render_to_buffer;
5
+ use blitz_paint::paint_scene;
6
+ use blitz_traits::shell::{Viewport};
7
+ use tokio::time::{timeout, Duration};
9
8
 
10
9
  use crate::image_size::ImageSize;
11
10
  use crate::logger::Logger;
12
11
  use crate::options::Options;
12
+ use crate::net_fetcher::NetFetcher;
13
13
 
14
14
  pub struct RenderOutput {
15
15
  pub buffer: Vec<u8>,
@@ -18,47 +18,45 @@ pub struct RenderOutput {
18
18
 
19
19
  pub async fn html_to_image(
20
20
  html: &str,
21
- base_url: Option<String>,
22
21
  options: Options,
23
22
  logger: &mut dyn Logger,
24
23
  ) -> RenderOutput {
25
- let (mut recv, callback) = MpscCallback::new();
26
- logger.log("Initial config");
24
+ let mut net_fetcher = if options.disable_fetch {
25
+ logger.log("Disabled fetching resources");
27
26
 
28
- let callback = Arc::new(callback);
29
- let net = Arc::new(Provider::new(callback));
30
- logger.log("Setup blitz-net Provider");
27
+ None
28
+ } else {
29
+ let fetcher = NetFetcher::new();
30
+ logger.log("Setup remote resource fetcher");
31
31
 
32
- let navigation_provider = Arc::new(DummyNavigationProvider);
33
- logger.log("Setup dummy navigation provider");
32
+ Some(fetcher)
33
+ };
34
34
 
35
35
  // Create HtmlDocument
36
36
  let mut document = HtmlDocument::from_html(
37
37
  &html,
38
- base_url,
39
- Vec::new(),
40
- Arc::clone(&net) as SharedProvider<Resource>,
41
- None,
42
- navigation_provider,
38
+ DocumentConfig {
39
+ base_url: options.base_url,
40
+ net_provider: net_fetcher.as_ref().map(|fetcher| fetcher.get_provider() as _),
41
+ ..Default::default()
42
+ },
43
43
  );
44
44
  logger.log("Parsed document");
45
45
 
46
46
  document.as_mut().set_viewport(Viewport::new(
47
47
  options.image_size.scaled_width(),
48
48
  options.image_size.scaled_height(),
49
- options.image_size.hidpi_scale,
49
+ options.image_size.hidpi_scale as f32,
50
50
  options.color_scheme,
51
51
  ));
52
52
 
53
- while !net.is_empty() {
54
- let Some((_, res)) = recv.recv().await else {
55
- break;
56
- };
57
- document.as_mut().load_resource(res);
53
+ if let Some(ref mut net_fetcher) = net_fetcher {
54
+ match timeout(Duration::from_millis((options.fetch_timeout * 1000.0) as u64), net_fetcher.fetch_resources(&mut document)).await {
55
+ Ok(_) => logger.log("Fetched assets"),
56
+ Err(_) => logger.log("Timeout fetching assets"),
57
+ }
58
58
  }
59
59
 
60
- logger.log("Fetched assets");
61
-
62
60
  // Compute style, layout, etc for HtmlDocument
63
61
  document.as_mut().resolve();
64
62
  logger.log("Resolved styles and layout");
@@ -81,16 +79,17 @@ pub async fn html_to_image(
81
79
  }
82
80
 
83
81
  // Render document to RGBA buffer
84
- let buffer = render_to_buffer(
85
- document.as_ref(),
86
- Viewport::new(
82
+ let buffer = render_to_buffer::<VelloCpuImageRenderer, _>(
83
+ |scene| paint_scene(
84
+ scene,
85
+ document.as_ref(),
86
+ render_size.hidpi_scale,
87
87
  render_size.scaled_width(),
88
88
  render_size.scaled_height(),
89
- render_size.hidpi_scale,
90
- ColorScheme::Light,
91
89
  ),
92
- )
93
- .await;
90
+ render_size.scaled_width(),
91
+ render_size.scaled_height(),
92
+ );
94
93
 
95
94
  logger.log("Rendered to buffer");
96
95
 
@@ -2,7 +2,7 @@
2
2
  pub struct ImageSize {
3
3
  pub width: u32,
4
4
  pub height: u32,
5
- pub hidpi_scale: f32,
5
+ pub hidpi_scale: f64,
6
6
  }
7
7
 
8
8
  impl ImageSize {