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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b2129ecb9c51fef4cb5937b84cb79ffb17880b514f787870272e152f27c75f3
4
- data.tar.gz: 72f3bf4d34326c362093a94ef77dbb460ef766930465cf04c7db6a3cff1a5dd4
3
+ metadata.gz: 7884a5777dcf5c83efbabe6e832f6276fc83450d6807199f51a73567e1f40123
4
+ data.tar.gz: 850e6467c3b7e76ae460fe4078bf3a5acd3cd3e0b0eb1bec898150671be9e7d1
5
5
  SHA512:
6
- metadata.gz: 1d37eedb7061da5062c3115256f53d9011ba7498b45ca4c2d83e61838c81f87261561c7e3b8bdfc7eac0c8241a66d1b5c8413fc36fe0cda67bbc639ae254a366
7
- data.tar.gz: 539f6f154e7414412e4c5b86505bededd930398a9f909d489787b395493a774bc1786011a1056689b75f61c38a4aa24de3b0e727cf88e66a8f85c9a16d55f55d
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
@@ -857,7 +857,7 @@ checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
857
857
 
858
858
  [[package]]
859
859
  name = "himg"
860
- version = "0.0.6"
860
+ version = "0.0.7"
861
861
  dependencies = [
862
862
  "anyrender",
863
863
  "anyrender_vello_cpu",
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 on the GPU. No browser, no fuss.
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
  ![Mockup showing HTML being transformed into a WhatsApp preview](/readme_hero.svg)
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
- 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
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
@@ -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.6"
4
+ version = "0.0.7"
5
5
  edition = "2024"
6
6
  authors = ["James Edwards-Jones <git@jamedjo.co.uk>"]
7
7
  license = "MIT"
@@ -34,6 +34,7 @@ async fn main() {
34
34
  verbose: true,
35
35
  color_scheme: ColorScheme::Light,
36
36
  disable_fetch: false,
37
+ fetch_timeout: 10.0,
37
38
  base_url: Some(base_url),
38
39
  };
39
40
 
@@ -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
- logger.log("Fetched assets");
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", 720)?,
30
- height: hash.lookup2("height", 405)?,
31
- hidpi_scale: 1.0,
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", true)?,
34
- verbose: hash.lookup2("verbose", false)?,
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", false)?,
37
- color_scheme: ColorScheme::Light,
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)
@@ -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
  }
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.5)
4
+ himg (0.0.6)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.5)
4
+ himg (0.0.6)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.5)
4
+ himg (0.0.6)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.5)
4
+ himg (0.0.6)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.5)
4
+ himg (0.0.6)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.5)
4
+ himg (0.0.6)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Himg
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
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.6
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: The Hyper Image Generator
235
+ summary: Renders HTML to an Image, perfect for OpenGraph social cards
233
236
  test_files: []