himg 0.0.10 → 0.0.12

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.6)
4
+ himg (0.0.11)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -72,10 +72,6 @@ GEM
72
72
  i18n (>= 1.6, < 2)
73
73
  minitest (>= 5.1)
74
74
  tzinfo (~> 2.0)
75
- appraisal (2.5.0)
76
- bundler
77
- rake
78
- thor (>= 0.14.0)
79
75
  ast (2.4.3)
80
76
  base64 (0.2.0)
81
77
  bigdecimal (1.4.4)
@@ -83,7 +79,6 @@ GEM
83
79
  bump (0.10.0)
84
80
  concurrent-ruby (1.3.4)
85
81
  crass (1.0.6)
86
- csv (3.3.4)
87
82
  date (3.4.1)
88
83
  debug (1.10.0)
89
84
  irb (~> 1.10)
@@ -91,15 +86,6 @@ GEM
91
86
  diff-lcs (1.6.1)
92
87
  drb (2.2.1)
93
88
  erubi (1.13.1)
94
- ffi (1.17.2-aarch64-linux-gnu)
95
- ffi (1.17.2-aarch64-linux-musl)
96
- ffi (1.17.2-arm-linux-gnu)
97
- ffi (1.17.2-arm-linux-musl)
98
- ffi (1.17.2-arm64-darwin)
99
- ffi (1.17.2-x86_64-darwin)
100
- ffi (1.17.2-x86_64-linux-gnu)
101
- ffi (1.17.2-x86_64-linux-musl)
102
- fileutils (1.7.3)
103
89
  globalid (1.2.1)
104
90
  activesupport (>= 6.1)
105
91
  i18n (1.14.7)
@@ -112,10 +98,6 @@ GEM
112
98
  json (2.10.2)
113
99
  language_server-protocol (3.17.0.4)
114
100
  lint_roller (1.1.0)
115
- listen (3.9.0)
116
- rb-fsevent (~> 0.10, >= 0.10.3)
117
- rb-inotify (~> 0.9, >= 0.9.10)
118
- logger (1.7.0)
119
101
  loofah (2.24.0)
120
102
  crass (~> 1.0.2)
121
103
  nokogiri (>= 1.12.0)
@@ -203,13 +185,8 @@ GEM
203
185
  rake-compiler (1.3.0)
204
186
  rake
205
187
  rake-compiler-dock (1.9.1)
206
- rb-fsevent (0.11.2)
207
- rb-inotify (0.11.1)
208
- ffi (~> 1.0)
209
188
  rb_sys (0.9.111)
210
189
  rake-compiler-dock (= 1.9.1)
211
- rbs (3.9.2)
212
- logger
213
190
  rdoc (6.13.1)
214
191
  psych (>= 4.0.0)
215
192
  regexp_parser (2.10.0)
@@ -251,28 +228,7 @@ GEM
251
228
  parser (>= 3.3.7.2)
252
229
  prism (~> 1.4)
253
230
  ruby-progressbar (1.13.0)
254
- securerandom (0.4.1)
255
- steep (1.10.0)
256
- activesupport (>= 5.1)
257
- concurrent-ruby (>= 1.1.10)
258
- csv (>= 3.0.9)
259
- fileutils (>= 1.1.0)
260
- json (>= 2.1.0)
261
- language_server-protocol (>= 3.17.0.4, < 4.0)
262
- listen (~> 3.0)
263
- logger (>= 1.3.0)
264
- mutex_m (>= 0.3.0)
265
- parser (>= 3.1)
266
- rainbow (>= 2.2.2, < 4.0)
267
- rbs (~> 3.9)
268
- securerandom (>= 0.1)
269
- strscan (>= 1.0.0)
270
- terminal-table (>= 2, < 5)
271
- uri (>= 0.12.0)
272
231
  stringio (3.1.7)
273
- strscan (3.1.3)
274
- terminal-table (4.0.0)
275
- unicode-display_width (>= 1.1.1, < 4)
276
232
  thor (1.3.2)
277
233
  timeout (0.4.3)
278
234
  tzinfo (2.0.6)
@@ -280,7 +236,6 @@ GEM
280
236
  unicode-display_width (3.1.4)
281
237
  unicode-emoji (~> 4.0, >= 4.0.4)
282
238
  unicode-emoji (4.0.4)
283
- uri (1.0.3)
284
239
  websocket-driver (0.7.7)
285
240
  base64
286
241
  websocket-extensions (>= 0.1.0)
@@ -298,7 +253,6 @@ PLATFORMS
298
253
  x86_64-linux-musl
299
254
 
300
255
  DEPENDENCIES
301
- appraisal
302
256
  bigdecimal (~> 1.4)
303
257
  bump
304
258
  concurrent-ruby (= 1.3.4)
@@ -306,13 +260,14 @@ DEPENDENCIES
306
260
  drb
307
261
  himg!
308
262
  irb
263
+ mutex_m
309
264
  rails (~> 7.0.0)
310
265
  rake
311
266
  rake-compiler
312
267
  rspec
313
268
  rspec-rails (~> 7.0)
314
269
  rubocop
315
- steep
270
+ thor
316
271
 
317
272
  BUNDLED WITH
318
273
  2.6.7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.6)
4
+ himg (0.0.11)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -84,10 +84,6 @@ GEM
84
84
  mutex_m
85
85
  securerandom (>= 0.3)
86
86
  tzinfo (~> 2.0)
87
- appraisal (2.5.0)
88
- bundler
89
- rake
90
- thor (>= 0.14.0)
91
87
  ast (2.4.3)
92
88
  base64 (0.2.0)
93
89
  benchmark (0.4.0)
@@ -97,7 +93,6 @@ GEM
97
93
  concurrent-ruby (1.3.5)
98
94
  connection_pool (2.5.1)
99
95
  crass (1.0.6)
100
- csv (3.3.4)
101
96
  date (3.4.1)
102
97
  debug (1.10.0)
103
98
  irb (~> 1.10)
@@ -105,15 +100,6 @@ GEM
105
100
  diff-lcs (1.6.1)
106
101
  drb (2.2.1)
107
102
  erubi (1.13.1)
108
- ffi (1.17.2-aarch64-linux-gnu)
109
- ffi (1.17.2-aarch64-linux-musl)
110
- ffi (1.17.2-arm-linux-gnu)
111
- ffi (1.17.2-arm-linux-musl)
112
- ffi (1.17.2-arm64-darwin)
113
- ffi (1.17.2-x86_64-darwin)
114
- ffi (1.17.2-x86_64-linux-gnu)
115
- ffi (1.17.2-x86_64-linux-musl)
116
- fileutils (1.7.3)
117
103
  globalid (1.2.1)
118
104
  activesupport (>= 6.1)
119
105
  i18n (1.14.7)
@@ -126,9 +112,6 @@ GEM
126
112
  json (2.10.2)
127
113
  language_server-protocol (3.17.0.4)
128
114
  lint_roller (1.1.0)
129
- listen (3.9.0)
130
- rb-fsevent (~> 0.10, >= 0.10.3)
131
- rb-inotify (~> 0.9, >= 0.9.10)
132
115
  logger (1.7.0)
133
116
  loofah (2.24.0)
134
117
  crass (~> 1.0.2)
@@ -222,13 +205,8 @@ GEM
222
205
  rake-compiler (1.3.0)
223
206
  rake
224
207
  rake-compiler-dock (1.9.1)
225
- rb-fsevent (0.11.2)
226
- rb-inotify (0.11.1)
227
- ffi (~> 1.0)
228
208
  rb_sys (0.9.111)
229
209
  rake-compiler-dock (= 1.9.1)
230
- rbs (3.9.2)
231
- logger
232
210
  rdoc (6.13.1)
233
211
  psych (>= 4.0.0)
234
212
  regexp_parser (2.10.0)
@@ -271,27 +249,7 @@ GEM
271
249
  prism (~> 1.4)
272
250
  ruby-progressbar (1.13.0)
273
251
  securerandom (0.4.1)
274
- steep (1.10.0)
275
- activesupport (>= 5.1)
276
- concurrent-ruby (>= 1.1.10)
277
- csv (>= 3.0.9)
278
- fileutils (>= 1.1.0)
279
- json (>= 2.1.0)
280
- language_server-protocol (>= 3.17.0.4, < 4.0)
281
- listen (~> 3.0)
282
- logger (>= 1.3.0)
283
- mutex_m (>= 0.3.0)
284
- parser (>= 3.1)
285
- rainbow (>= 2.2.2, < 4.0)
286
- rbs (~> 3.9)
287
- securerandom (>= 0.1)
288
- strscan (>= 1.0.0)
289
- terminal-table (>= 2, < 5)
290
- uri (>= 0.12.0)
291
252
  stringio (3.1.7)
292
- strscan (3.1.3)
293
- terminal-table (4.0.0)
294
- unicode-display_width (>= 1.1.1, < 4)
295
253
  thor (1.3.2)
296
254
  timeout (0.4.3)
297
255
  tzinfo (2.0.6)
@@ -299,7 +257,6 @@ GEM
299
257
  unicode-display_width (3.1.4)
300
258
  unicode-emoji (~> 4.0, >= 4.0.4)
301
259
  unicode-emoji (4.0.4)
302
- uri (1.0.3)
303
260
  websocket-driver (0.7.7)
304
261
  base64
305
262
  websocket-extensions (>= 0.1.0)
@@ -317,7 +274,6 @@ PLATFORMS
317
274
  x86_64-linux-musl
318
275
 
319
276
  DEPENDENCIES
320
- appraisal
321
277
  bump
322
278
  debug
323
279
  himg!
@@ -328,7 +284,7 @@ DEPENDENCIES
328
284
  rspec
329
285
  rspec-rails (~> 7.0)
330
286
  rubocop
331
- steep
287
+ thor
332
288
 
333
289
  BUNDLED WITH
334
290
  2.6.7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.6)
4
+ himg (0.0.11)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -78,10 +78,6 @@ GEM
78
78
  minitest (>= 5.1)
79
79
  securerandom (>= 0.3)
80
80
  tzinfo (~> 2.0, >= 2.0.5)
81
- appraisal (2.5.0)
82
- bundler
83
- rake
84
- thor (>= 0.14.0)
85
81
  ast (2.4.3)
86
82
  base64 (0.2.0)
87
83
  benchmark (0.4.0)
@@ -91,7 +87,6 @@ GEM
91
87
  concurrent-ruby (1.3.5)
92
88
  connection_pool (2.5.1)
93
89
  crass (1.0.6)
94
- csv (3.3.4)
95
90
  date (3.4.1)
96
91
  debug (1.10.0)
97
92
  irb (~> 1.10)
@@ -99,15 +94,6 @@ GEM
99
94
  diff-lcs (1.6.1)
100
95
  drb (2.2.1)
101
96
  erubi (1.13.1)
102
- ffi (1.17.2-aarch64-linux-gnu)
103
- ffi (1.17.2-aarch64-linux-musl)
104
- ffi (1.17.2-arm-linux-gnu)
105
- ffi (1.17.2-arm-linux-musl)
106
- ffi (1.17.2-arm64-darwin)
107
- ffi (1.17.2-x86_64-darwin)
108
- ffi (1.17.2-x86_64-linux-gnu)
109
- ffi (1.17.2-x86_64-linux-musl)
110
- fileutils (1.7.3)
111
97
  globalid (1.2.1)
112
98
  activesupport (>= 6.1)
113
99
  i18n (1.14.7)
@@ -120,9 +106,6 @@ GEM
120
106
  json (2.10.2)
121
107
  language_server-protocol (3.17.0.4)
122
108
  lint_roller (1.1.0)
123
- listen (3.9.0)
124
- rb-fsevent (~> 0.10, >= 0.10.3)
125
- rb-inotify (~> 0.9, >= 0.9.10)
126
109
  logger (1.7.0)
127
110
  loofah (2.24.0)
128
111
  crass (~> 1.0.2)
@@ -135,7 +118,6 @@ GEM
135
118
  marcel (1.0.4)
136
119
  mini_mime (1.1.5)
137
120
  minitest (5.25.5)
138
- mutex_m (0.3.0)
139
121
  net-imap (0.5.6)
140
122
  date
141
123
  net-protocol
@@ -216,13 +198,8 @@ GEM
216
198
  rake-compiler (1.3.0)
217
199
  rake
218
200
  rake-compiler-dock (1.9.1)
219
- rb-fsevent (0.11.2)
220
- rb-inotify (0.11.1)
221
- ffi (~> 1.0)
222
201
  rb_sys (0.9.111)
223
202
  rake-compiler-dock (= 1.9.1)
224
- rbs (3.9.2)
225
- logger
226
203
  rdoc (6.13.1)
227
204
  psych (>= 4.0.0)
228
205
  regexp_parser (2.10.0)
@@ -265,27 +242,7 @@ GEM
265
242
  prism (~> 1.4)
266
243
  ruby-progressbar (1.13.0)
267
244
  securerandom (0.4.1)
268
- steep (1.10.0)
269
- activesupport (>= 5.1)
270
- concurrent-ruby (>= 1.1.10)
271
- csv (>= 3.0.9)
272
- fileutils (>= 1.1.0)
273
- json (>= 2.1.0)
274
- language_server-protocol (>= 3.17.0.4, < 4.0)
275
- listen (~> 3.0)
276
- logger (>= 1.3.0)
277
- mutex_m (>= 0.3.0)
278
- parser (>= 3.1)
279
- rainbow (>= 2.2.2, < 4.0)
280
- rbs (~> 3.9)
281
- securerandom (>= 0.1)
282
- strscan (>= 1.0.0)
283
- terminal-table (>= 2, < 5)
284
- uri (>= 0.12.0)
285
245
  stringio (3.1.7)
286
- strscan (3.1.3)
287
- terminal-table (4.0.0)
288
- unicode-display_width (>= 1.1.1, < 4)
289
246
  thor (1.3.2)
290
247
  timeout (0.4.3)
291
248
  tzinfo (2.0.6)
@@ -293,7 +250,6 @@ GEM
293
250
  unicode-display_width (3.1.4)
294
251
  unicode-emoji (~> 4.0, >= 4.0.4)
295
252
  unicode-emoji (4.0.4)
296
- uri (1.0.3)
297
253
  useragent (0.16.11)
298
254
  websocket-driver (0.7.7)
299
255
  base64
@@ -312,7 +268,6 @@ PLATFORMS
312
268
  x86_64-linux-musl
313
269
 
314
270
  DEPENDENCIES
315
- appraisal
316
271
  bump
317
272
  debug
318
273
  himg!
@@ -323,7 +278,7 @@ DEPENDENCIES
323
278
  rspec
324
279
  rspec-rails (~> 7.0)
325
280
  rubocop
326
- steep
281
+ thor
327
282
 
328
283
  BUNDLED WITH
329
284
  2.6.7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- himg (0.0.6)
4
+ himg (0.0.11)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -78,10 +78,6 @@ GEM
78
78
  securerandom (>= 0.3)
79
79
  tzinfo (~> 2.0, >= 2.0.5)
80
80
  uri (>= 0.13.1)
81
- appraisal (2.5.0)
82
- bundler
83
- rake
84
- thor (>= 0.14.0)
85
81
  ast (2.4.3)
86
82
  base64 (0.2.0)
87
83
  benchmark (0.4.0)
@@ -91,7 +87,6 @@ GEM
91
87
  concurrent-ruby (1.3.5)
92
88
  connection_pool (2.5.1)
93
89
  crass (1.0.6)
94
- csv (3.3.4)
95
90
  date (3.4.1)
96
91
  debug (1.10.0)
97
92
  irb (~> 1.10)
@@ -99,15 +94,6 @@ GEM
99
94
  diff-lcs (1.6.1)
100
95
  drb (2.2.1)
101
96
  erubi (1.13.1)
102
- ffi (1.17.2-aarch64-linux-gnu)
103
- ffi (1.17.2-aarch64-linux-musl)
104
- ffi (1.17.2-arm-linux-gnu)
105
- ffi (1.17.2-arm-linux-musl)
106
- ffi (1.17.2-arm64-darwin)
107
- ffi (1.17.2-x86_64-darwin)
108
- ffi (1.17.2-x86_64-linux-gnu)
109
- ffi (1.17.2-x86_64-linux-musl)
110
- fileutils (1.7.3)
111
97
  globalid (1.2.1)
112
98
  activesupport (>= 6.1)
113
99
  i18n (1.14.7)
@@ -120,9 +106,6 @@ GEM
120
106
  json (2.10.2)
121
107
  language_server-protocol (3.17.0.4)
122
108
  lint_roller (1.1.0)
123
- listen (3.9.0)
124
- rb-fsevent (~> 0.10, >= 0.10.3)
125
- rb-inotify (~> 0.9, >= 0.9.10)
126
109
  logger (1.7.0)
127
110
  loofah (2.24.0)
128
111
  crass (~> 1.0.2)
@@ -135,7 +118,6 @@ GEM
135
118
  marcel (1.0.4)
136
119
  mini_mime (1.1.5)
137
120
  minitest (5.25.5)
138
- mutex_m (0.3.0)
139
121
  net-imap (0.5.6)
140
122
  date
141
123
  net-protocol
@@ -216,13 +198,8 @@ GEM
216
198
  rake-compiler (1.3.0)
217
199
  rake
218
200
  rake-compiler-dock (1.9.1)
219
- rb-fsevent (0.11.2)
220
- rb-inotify (0.11.1)
221
- ffi (~> 1.0)
222
201
  rb_sys (0.9.111)
223
202
  rake-compiler-dock (= 1.9.1)
224
- rbs (3.9.2)
225
- logger
226
203
  rdoc (6.13.1)
227
204
  psych (>= 4.0.0)
228
205
  regexp_parser (2.10.0)
@@ -265,27 +242,7 @@ GEM
265
242
  prism (~> 1.4)
266
243
  ruby-progressbar (1.13.0)
267
244
  securerandom (0.4.1)
268
- steep (1.10.0)
269
- activesupport (>= 5.1)
270
- concurrent-ruby (>= 1.1.10)
271
- csv (>= 3.0.9)
272
- fileutils (>= 1.1.0)
273
- json (>= 2.1.0)
274
- language_server-protocol (>= 3.17.0.4, < 4.0)
275
- listen (~> 3.0)
276
- logger (>= 1.3.0)
277
- mutex_m (>= 0.3.0)
278
- parser (>= 3.1)
279
- rainbow (>= 2.2.2, < 4.0)
280
- rbs (~> 3.9)
281
- securerandom (>= 0.1)
282
- strscan (>= 1.0.0)
283
- terminal-table (>= 2, < 5)
284
- uri (>= 0.12.0)
285
245
  stringio (3.1.7)
286
- strscan (3.1.3)
287
- terminal-table (4.0.0)
288
- unicode-display_width (>= 1.1.1, < 4)
289
246
  thor (1.3.2)
290
247
  timeout (0.4.3)
291
248
  tzinfo (2.0.6)
@@ -312,7 +269,6 @@ PLATFORMS
312
269
  x86_64-linux-musl
313
270
 
314
271
  DEPENDENCIES
315
- appraisal
316
272
  bump
317
273
  debug
318
274
  himg!
@@ -323,7 +279,7 @@ DEPENDENCIES
323
279
  rspec
324
280
  rspec-rails (~> 7.0)
325
281
  rubocop
326
- steep
282
+ thor
327
283
 
328
284
  BUNDLED WITH
329
285
  2.6.7
data/lib/himg/cli.rb CHANGED
@@ -1,10 +1,25 @@
1
1
  require "thor"
2
2
  require "himg"
3
3
  require "open-uri"
4
+ require "uri"
4
5
 
5
6
  module Himg
6
7
  class CLI < Thor
7
- desc "screenshot SOURCE_HTML DESTINATION_PNG [OPTIONS]", "Render HTML to a png screenshot"
8
+ CLI_ONLY_OPTIONS = [:stdin, :http_headers].freeze
9
+
10
+ default_command :usage
11
+
12
+ desc "usage", "Show usage for screenshot command", hide: true
13
+ def usage
14
+ puts "himg v#{VERSION}"
15
+ puts
16
+ puts "Converts HTML to PNG images using a lightweight, minimal renderer."
17
+ puts "Ideal for generating OpenGraph images from purpose-built HTML."
18
+ puts
19
+ CLI.command_help(Thor::Base.shell.new, 'screenshot')
20
+ end
21
+
22
+ desc "screenshot [SOURCE_HTML] DESTINATION_PNG [OPTIONS]", "Render HTML to a png screenshot"
8
23
 
9
24
  option :width, type: :numeric, desc: "Sets the width of the rendered content.", default: 720
10
25
  option :height, type: :numeric, desc: "Sets the desired height of the rendered output.", default: 405
@@ -13,22 +28,39 @@ module Himg
13
28
  option :disable_fetch, type: :boolean, desc: "Skip fetching file/http resources (stylesheets, images, fonts, etc)", default: false
14
29
  option :fetch_timeout, type: :numeric, desc: "Timeout in seconds for fetching resources", default: 10
15
30
  option :gpu, type: :boolean, desc: "Use GPU renderer instead of CPU renderer", default: false
16
- option :http_headers, desc: "HTTP Headers to use when fetching remote resource"
31
+ option :http_headers, type: :hash, desc: "HTTP headers sent when fetching the SOURCE_HTML (e.g. --http-headers \"Authorization: Bearer token\" \"Content-Type: application/json\")"
17
32
  option :base_url, desc: "Base URL used to resolve relative URLs"
33
+ option :stdin, type: :boolean, desc: "Read HTML content from stdin instead of a file", default: false
18
34
 
19
35
  long_desc <<-LONGDESC
20
36
  `himg screenshot` takes a path to an HTML file and will render a png image with the output.
21
37
 
22
- It takes a SOURCE, which can be a file path or a URL to fetch.
38
+ It takes a SOURCE, which can be a file path, a URL to fetch, or piped from stdin.
39
+
40
+ If SOURCE_HTML is omitted, HTML content will be read from stdin.
41
+ You can also use the --stdin option to explicitly read from stdin.
23
42
 
24
43
  The DESTINATION_PNG must be a local file path.
25
44
 
45
+ Examples:
46
+ himg screenshot input.html output.png
47
+ himg screenshot https://himg.jamedjo.co.uk output.png
48
+ echo '<h1>Hello</h1>' | himg screenshot --stdin output.png
49
+
26
50
  CAVEATS: This uses a lightweight HTML parser instead of a full browser, so does not support all features.
27
51
  Additionally it does not use a JavaScript engine, so will screenshot the page as-is and would not work for all webpages.
28
52
  LONGDESC
29
- def screenshot(url, destination)
53
+ def screenshot(first_arg = nil, second_arg = nil)
54
+ url, destination = parse_screenshot_args(first_arg, second_arg)
55
+
56
+ options[:http_headers]&.transform_values!(&:strip)
57
+
30
58
  Document.new(url, options).load do |content|
31
- png = Himg.render(content, **options.transform_keys(&:to_sym))
59
+ render_options = options.transform_keys(&:to_sym)
60
+ .reject { |k, _| CLI_ONLY_OPTIONS.include?(k) }
61
+ render_options[:base_url] ||= base_directory_url(url) if Document.http_url?(url)
62
+
63
+ png = Himg.render(content, **render_options)
32
64
 
33
65
  File.open(destination, "wb") { |f| f.write(png) }
34
66
  end
@@ -36,6 +68,28 @@ module Himg
36
68
 
37
69
  private
38
70
 
71
+ def parse_screenshot_args(first_arg, second_arg)
72
+ raise Thor::RequiredArgumentMissingError unless first_arg
73
+
74
+ case
75
+ when options[:stdin]
76
+ raise Thor::RequiredArgumentMissingError if second_arg
77
+ [nil, first_arg]
78
+ when second_arg
79
+ [first_arg, second_arg]
80
+ else
81
+ raise Thor::RequiredArgumentMissingError if $stdin.tty?
82
+ [nil, first_arg]
83
+ end
84
+ rescue Thor::RequiredArgumentMissingError
85
+ CLI.command_help(Thor::Base.shell.new, 'screenshot')
86
+ raise
87
+ end
88
+
89
+ def base_directory_url(url)
90
+ URI.join(url, ".").to_s
91
+ end
92
+
39
93
  def self.exit_on_failure?
40
94
  true
41
95
  end
@@ -44,15 +98,25 @@ module Himg
44
98
  def initialize(source, options)
45
99
  @source = source
46
100
  @options = options
101
+ @http_headers = options[:http_headers]
102
+ end
103
+
104
+ def self.http_url?(url)
105
+ url.to_s =~ %r{\Ahttps?\://}
47
106
  end
48
107
 
49
- def http_url?
50
- @source =~ %r{\Ahttps?\://}
108
+ def stdin?
109
+ @source.nil?
51
110
  end
52
111
 
53
112
  def load(&block)
54
- if http_url?
55
- URI.send(:open, @source) do |input|
113
+ if stdin?
114
+ yield($stdin.read)
115
+ elsif self.class.http_url?(@source)
116
+ args = [@source]
117
+ args << @http_headers if @http_headers
118
+
119
+ URI.open(*args) do |input|
56
120
  yield(input.binmode.read)
57
121
  end
58
122
  else
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.10"
4
+ VERSION = "0.0.12"
5
5
  end
data/lib/himg.rb CHANGED
@@ -22,6 +22,7 @@ module Himg
22
22
  class GpuNotFound < Error; end
23
23
 
24
24
  def self.render(html, width: 720, height: 405, truncate: true, verbose: false, base_url: nil, disable_fetch: false, fetch_timeout: 10, gpu: false)
25
- 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, "gpu" => gpu)
25
+ @default_renderer ||= Renderer.new
26
+ @default_renderer.render(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, "gpu" => gpu)
26
27
  end
27
28
  end
data/logo.svg ADDED
@@ -0,0 +1,57 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg width="220" height="80" viewBox="0 0 220 80" version="1.1" id="svg32" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
3
+ <defs id="defs14">
4
+ <linearGradient id="waveGradient" x1="0%" y1="0%" x2="100%" y2="0%">
5
+ <stop offset="0%" stop-color="#FF006E" id="stop2" />
6
+ <stop offset="50%" stop-color="#8338EC" id="stop4" />
7
+ <stop offset="100%" stop-color="#3A86FF" id="stop6" />
8
+ </linearGradient>
9
+ <linearGradient id="borderGradient" x1="0%" y1="0%" x2="100%" y2="0%">
10
+ <stop offset="0%" stop-color="#8338EC" id="stop9" />
11
+ <stop offset="100%" stop-color="#3A86FF" id="stop11" />
12
+ </linearGradient>
13
+ </defs>
14
+
15
+ <!-- H letter -->
16
+ <g aria-label="H" id="text16" style="font-weight:800;font-size:72px;font-family:'Noto Sans';fill:#ff006e">
17
+ <path
18
+ d="M 48.6,60 H 37.728 V 37.824 H 17.352 V 60 H 6.48 V 8.592 h 10.872 v 20.16 H 37.728 V 8.592 H 48.6 Z"
19
+ id="path36" />
20
+ </g>
21
+
22
+ <!-- Flowing wave connector centered on H -->
23
+ <g transform="translate(60,5)" id="g22">
24
+ <svg width="120" height="60" viewBox="0 0 120 60" version="1.1" id="svg20">
25
+ <path d="m 0,30 q 30,-20 60,0 30,20 60,0" stroke="url(#waveGradient)" stroke-width="4" fill="none" id="path18">
26
+ <animate
27
+ attributeName="d"
28
+ values="M 0 30 Q 30 10, 60 30 T 120 30; M 0 30 Q 30 50, 60 30 T 120 30; M 0 30 Q 30 10, 60 30 T 120 30"
29
+ dur="3s"
30
+ repeatCount="indefinite" />
31
+ </path>
32
+ </svg>
33
+ </g>
34
+ <g transform="translate(160,35)" id="g30">
35
+
36
+ <!-- Background for gradient border -->
37
+ <path id="rect24" style="fill:url(#borderGradient)"
38
+ d="m -10,-20 h 40 c 11.08,0 20,8.92 20,20 0,11.08 -8.92,20 -20,20 h -40 c -11.08,0 -20,-8.92 -20,-20 0,-11.08 8.92,-20 20,-20 z" />
39
+
40
+ <!-- White fill on top with 2px border -->
41
+ <path id="rect26" style="fill:#ffffff"
42
+ d="m -10,-18 h 40 c 9.972,0 18,8.028 18,18 0,9.972 -8.028,18 -18,18 h -40 c -9.972,0 -18,-8.028 -18,-18 0,-9.972 8.028,-18 18,-18 z" />
43
+
44
+ <!-- "img" text -->
45
+ <g aria-label="img" id="text28" style="font-weight:700;font-size:24px;font-family:'Noto Sans';text-anchor:middle;fill:#333333">
46
+ <path
47
+ d="m -9.3680009,-10.24 q 0.792,0 1.368,0.384 0.576,0.36 0.576,1.368 0,0.984 -0.576,1.368 -0.576,0.384 -1.368,0.384 -0.8160001,0 -1.3920001,-0.384 -0.552,-0.384 -0.552,-1.368 0,-1.008 0.552,-1.368 0.576,-0.384 1.3920001,-0.384 z m 1.776,5.136 V 8 H -11.168001 V -5.104 Z"
48
+ id="path41" />
49
+ <path
50
+ d="m 11.536006,-5.344 q 2.232,0 3.36,1.152 1.152,1.128 1.152,3.648 V 8 h -3.576 V 0.344 q 0,-2.832 -1.968,-2.832 -1.4159996,0 -2.0159996,1.008 -0.6,1.008 -0.6,2.904 V 8 h -3.576 V 0.344 q 0,-2.832 -1.968,-2.832 -1.48799999,0 -2.06399999,1.128 -0.552,1.104 -0.552,3.192 V 8 H -3.8479936 V -5.104 h 2.736 l 0.48000001,1.68 h 0.192 q 0.6,-1.008 1.63199999,-1.464 1.056,-0.456 2.184,-0.456 1.44,0 2.448,0.48 1.008,0.456 1.536,1.44 h 0.312 q 0.6,-1.008 1.656,-1.464 1.0799996,-0.456 2.2079996,-0.456 z"
51
+ id="path43" />
52
+ <path
53
+ d="m 23.968015,-5.344 q 2.424,0 3.792,1.92 h 0.096 l 0.288,-1.68 h 3.024 V 8.024 q 0,2.808 -1.656,4.272 -1.656,1.464 -4.896,1.464 -1.392,0 -2.592,-0.168 -1.176,-0.168 -2.304,-0.6 v -2.856 q 2.424,1.008 5.112,1.008 2.76,0 2.76,-2.976 V 7.904 q 0,-0.408 0.024,-0.84 0.048,-0.432 0.072,-0.768 h -0.096 q -0.672,1.032 -1.608,1.488 -0.936,0.456 -2.112,0.456 -2.328,0 -3.648,-1.776 -1.296,-1.8 -1.296,-4.992 0,-3.216 1.344,-5.016 1.344,-1.8 3.696,-1.8 z m 1.128,2.904 q -2.52,0 -2.52,3.96 0,3.912 2.568,3.912 1.368,0 2.016,-0.768 0.672,-0.792 0.672,-2.736 V 1.496 q 0,-2.112 -0.648,-3.024 -0.648,-0.912 -2.088,-0.912 z"
54
+ id="path45" />
55
+ </g>
56
+ </g>
57
+ </svg>