himg 0.0.6 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Cargo.lock +1 -1
- data/README.md +7 -4
- data/exe/himg +7 -0
- data/ext/himg/Cargo.toml +1 -1
- data/ext/himg/examples/file.rs +1 -0
- data/ext/himg/src/html_to_image.rs +5 -2
- data/ext/himg/src/lib.rs +8 -8
- data/ext/himg/src/options.rs +2 -0
- 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/cli.rb +1 -0
- data/lib/himg/version.rb +1 -1
- data/lib/himg.rb +2 -2
- metadata +7 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7884a5777dcf5c83efbabe6e832f6276fc83450d6807199f51a73567e1f40123
|
|
4
|
+
data.tar.gz: 850e6467c3b7e76ae460fe4078bf3a5acd3cd3e0b0eb1bec898150671be9e7d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b0befe957c4dda3e6b5c9d0a7aff0c112564cdb080bb040562c06f80ecd37e0f5340b96e8c30fda8d8a90ddeccc53381c4d740533c6a0848fb62b2a644cc2de3
|
|
7
|
+
data.tar.gz: 20574d4a615bed23e48027e23b79f77d5ffeef9f4e1ec75f294f38a370af772020fbacb1d4c90579b93f48f4293282d65466efe318b5fbee80bb8079630a10c5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.0.7] - 2025-07-29
|
|
4
|
+
|
|
5
|
+
- Added `fetch_timeout` option to control restrict how long can be spent fetching resources.
|
|
6
|
+
- Move bin/himg to exe/himg so bundler can install it in on the users PATH.
|
|
7
|
+
|
|
3
8
|
## [0.0.6] - 2025-07-23
|
|
4
9
|
|
|
5
10
|
- Added bin/himg CLI screenshot tool
|
data/Cargo.lock
CHANGED
data/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
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
|
|
5
|
+
Parses a minimal subset of HTML/CSS, fetches nested resources, renders an image. No browser, no fuss.
|
|
6
|
+
|
|
7
|
+
Perfect for OpenGraph images - stop losing clicks to boring links by adding a rich image preview that showcases your content.
|
|
6
8
|
|
|
7
9
|

|
|
8
10
|
|
|
@@ -11,8 +13,8 @@ Parses a minimal subset of HTML/CSS, fetches nested resources, renders an image
|
|
|
11
13
|
### Command Line
|
|
12
14
|
|
|
13
15
|
```bash
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
himg screenshot path/to/your.html screenshot.png
|
|
17
|
+
himg screenshot https://github.com/Jamedjo/himg himg.png --width=1024 --verbose --no-truncate
|
|
16
18
|
```
|
|
17
19
|
|
|
18
20
|
### Ruby
|
|
@@ -63,6 +65,7 @@ bundle add himg
|
|
|
63
65
|
|verbose | Enables detailed logging for debugging and profiling. | bool | false |
|
|
64
66
|
|base_url | Where relative paths are relative to for linked resources (stylesheets, images, fonts, etc) | string | nil |
|
|
65
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 |
|
|
66
69
|
|
|
67
70
|
|
|
68
71
|
### Passing options to a Rails view template
|
|
@@ -130,7 +133,7 @@ To play nicely with Rails a template handler is registered, which Rails' `defaul
|
|
|
130
133
|
|
|
131
134
|
## CAVEATS
|
|
132
135
|
|
|
133
|
-
1. This is **pre-alpha** software, don't expect it to work yet.
|
|
136
|
+
1. This is **pre-alpha** software, don't expect it to work perfectly yet.
|
|
134
137
|
2. Performance needs tuning. Both in the underlying blitz library and how data is passed between Rust and Ruby
|
|
135
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.
|
|
136
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.
|
data/exe/himg
ADDED
data/ext/himg/Cargo.toml
CHANGED
data/ext/himg/examples/file.rs
CHANGED
|
@@ -4,6 +4,7 @@ use anyrender_vello_cpu::VelloCpuImageRenderer;
|
|
|
4
4
|
use anyrender::render_to_buffer;
|
|
5
5
|
use blitz_paint::paint_scene;
|
|
6
6
|
use blitz_traits::shell::{Viewport};
|
|
7
|
+
use tokio::time::{timeout, Duration};
|
|
7
8
|
|
|
8
9
|
use crate::image_size::ImageSize;
|
|
9
10
|
use crate::logger::Logger;
|
|
@@ -50,8 +51,10 @@ pub async fn html_to_image(
|
|
|
50
51
|
));
|
|
51
52
|
|
|
52
53
|
if let Some(ref mut net_fetcher) = net_fetcher {
|
|
53
|
-
net_fetcher.fetch_resources(&mut document).await
|
|
54
|
-
|
|
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
|
+
}
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
// Compute style, layout, etc for HtmlDocument
|
data/ext/himg/src/lib.rs
CHANGED
|
@@ -12,7 +12,6 @@ pub use options::Options;
|
|
|
12
12
|
pub use html_to_image::html_to_image;
|
|
13
13
|
pub use writer::write_png;
|
|
14
14
|
|
|
15
|
-
use blitz_traits::shell::ColorScheme;
|
|
16
15
|
use magnus::{function, prelude::*, ExceptionClass, Error, Ruby, RString, RHash};
|
|
17
16
|
|
|
18
17
|
impl Options {
|
|
@@ -26,15 +25,16 @@ impl Options {
|
|
|
26
25
|
|
|
27
26
|
let options = Options {
|
|
28
27
|
image_size: ImageSize {
|
|
29
|
-
width: hash.lookup2("width",
|
|
30
|
-
height: hash.lookup2("height",
|
|
31
|
-
hidpi_scale:
|
|
28
|
+
width: hash.lookup2("width", defaults.image_size.width)?,
|
|
29
|
+
height: hash.lookup2("height", defaults.image_size.height)?,
|
|
30
|
+
hidpi_scale: defaults.image_size.hidpi_scale,
|
|
32
31
|
},
|
|
33
|
-
truncate: hash.lookup2("truncate",
|
|
34
|
-
verbose: hash.lookup2("verbose",
|
|
32
|
+
truncate: hash.lookup2("truncate", defaults.truncate)?,
|
|
33
|
+
verbose: hash.lookup2("verbose", defaults.verbose)?,
|
|
35
34
|
base_url: hash.lookup("base_url")?,
|
|
36
|
-
disable_fetch: hash.lookup2("disable_fetch",
|
|
37
|
-
|
|
35
|
+
disable_fetch: hash.lookup2("disable_fetch", defaults.disable_fetch)?,
|
|
36
|
+
fetch_timeout: hash.lookup2("fetch_timeout", defaults.fetch_timeout)?,
|
|
37
|
+
color_scheme: defaults.color_scheme,
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
Ok(options)
|
data/ext/himg/src/options.rs
CHANGED
|
@@ -7,6 +7,7 @@ pub struct Options {
|
|
|
7
7
|
pub image_size: ImageSize,
|
|
8
8
|
pub color_scheme: ColorScheme,
|
|
9
9
|
pub disable_fetch: bool,
|
|
10
|
+
pub fetch_timeout: f64,
|
|
10
11
|
pub base_url: Option<String>,
|
|
11
12
|
pub truncate: bool,
|
|
12
13
|
pub verbose: bool,
|
|
@@ -24,6 +25,7 @@ impl Options {
|
|
|
24
25
|
verbose: false,
|
|
25
26
|
base_url: None,
|
|
26
27
|
disable_fetch: false,
|
|
28
|
+
fetch_timeout: 10.0,
|
|
27
29
|
color_scheme: ColorScheme::Light,
|
|
28
30
|
}
|
|
29
31
|
}
|
data/lib/himg/cli.rb
CHANGED
|
@@ -11,6 +11,7 @@ module Himg
|
|
|
11
11
|
option :truncate, type: :boolean, desc: "Keeps the image height fixed instead of expanding to include the full page.", default: true
|
|
12
12
|
option :verbose, type: :boolean, desc: "Enables detailed logging for debugging and profiling.", default: false
|
|
13
13
|
option :disable_fetch, type: :boolean, desc: "Skip fetching file/http resources (stylesheets, images, fonts, etc)", default: false
|
|
14
|
+
option :fetch_timeout, type: :numeric, desc: "Timeout in seconds for fetching resources", default: 10
|
|
14
15
|
option :http_headers, desc: "HTTP Headers to use when fetching remote resource"
|
|
15
16
|
option :base_url, desc: "Base URL used to resolve relative URLs"
|
|
16
17
|
|
data/lib/himg/version.rb
CHANGED
data/lib/himg.rb
CHANGED
|
@@ -20,7 +20,7 @@ module Himg
|
|
|
20
20
|
RENDER_OPTIONS = %i[width height truncate verbose].freeze
|
|
21
21
|
class Error < StandardError; end
|
|
22
22
|
|
|
23
|
-
def self.render(html, width: 720, height: 405, truncate: true, verbose: false, base_url: nil, disable_fetch: false)
|
|
24
|
-
render_to_string(html, "width" => width.to_i, "height" => height.to_i, "truncate" => truncate, "verbose" => verbose, "base_url" => BaseUrl.new(base_url).to_s, "disable_fetch" => disable_fetch)
|
|
23
|
+
def self.render(html, width: 720, height: 405, truncate: true, verbose: false, base_url: nil, disable_fetch: false, fetch_timeout: 10)
|
|
24
|
+
render_to_string(html, "width" => width.to_i, "height" => height.to_i, "truncate" => truncate, "verbose" => verbose, "base_url" => BaseUrl.new(base_url).to_s, "disable_fetch" => disable_fetch, "fetch_timeout" => fetch_timeout.to_f)
|
|
25
25
|
end
|
|
26
26
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: himg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Edwards-Jones
|
|
@@ -149,10 +149,12 @@ dependencies:
|
|
|
149
149
|
- - ">="
|
|
150
150
|
- !ruby/object:Gem::Version
|
|
151
151
|
version: '0'
|
|
152
|
-
description: You give it HTML and it renders an Image!
|
|
152
|
+
description: You give it HTML and it renders an Image! No browser required. Perfect
|
|
153
|
+
for OpenGraph social cards so your links don't look boring when shared.
|
|
153
154
|
email:
|
|
154
155
|
- git@jamedjo.co.uk
|
|
155
|
-
executables:
|
|
156
|
+
executables:
|
|
157
|
+
- himg
|
|
156
158
|
extensions:
|
|
157
159
|
- ext/himg/extconf.rb
|
|
158
160
|
extra_rdoc_files: []
|
|
@@ -169,6 +171,7 @@ files:
|
|
|
169
171
|
- README.md
|
|
170
172
|
- Rakefile
|
|
171
173
|
- Steepfile
|
|
174
|
+
- exe/himg
|
|
172
175
|
- ext/himg/Cargo.lock
|
|
173
176
|
- ext/himg/Cargo.toml
|
|
174
177
|
- ext/himg/build.rs
|
|
@@ -229,5 +232,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
229
232
|
requirements: []
|
|
230
233
|
rubygems_version: 3.6.7
|
|
231
234
|
specification_version: 4
|
|
232
|
-
summary:
|
|
235
|
+
summary: Renders HTML to an Image, perfect for OpenGraph social cards
|
|
233
236
|
test_files: []
|