Skip to content

Commit 6b7fd05

Browse files
committed
Support node blob urls
1 parent e9e210f commit 6b7fd05

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Load images from:
2323
* Local file.
2424
* Data URI.
2525
* Http(s) URL.
26+
* Node.js Blob URL.
2627
* Raw RGBA pixel data
2728

2829

@@ -40,7 +41,18 @@ Additional features:
4041
const Image = require('image-raub');
4142
```
4243

43-
See [TypeSctipt defenitions](/index.d.ts) for more details.
44+
See [TypeScript defenitions](/index.d.ts) for more details.
45+
46+
47+
### Set window icon
48+
49+
Compatible with [glfw-raub](https://github.com/node-3d/glfw-raub) `window.icon` property.
50+
51+
```js
52+
const icon = new Image();
53+
icon.src = __dirname + '/icons/logo.png';
54+
icon.on('load', () => { window.icon = icon; });
55+
```
4456

4557

4658
### Load an OpenGL texture

js/image.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
const { inspect, inherits } = require('util');
4-
const Emitter = require('events');
5-
3+
const { resolveObjectURL } = require('node:buffer');
4+
const { inspect, inherits } = require('node:util');
5+
const Emitter = require('node:events');
66
const { download } = require('addon-tools-raub');
77

88
const { Image } = require('../core');
@@ -99,6 +99,17 @@ class JsImage extends Image {
9999
return;
100100
}
101101

102+
// Object URL
103+
if (/^blob:nodedata:/.test(this._src)) {
104+
const blob = resolveObjectURL(this._src);
105+
(async () => {
106+
const arrayBuffer = await blob.arrayBuffer();
107+
const buffer = Buffer.from(arrayBuffer);
108+
this._load(buffer);
109+
})();
110+
return;
111+
}
112+
102113
// Data URI
103114
if (/^data:/.test(this._src)) {
104115
this._isDataUri = true;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Luis Blanco <luisblanco1337@gmail.com>",
33
"name": "image-raub",
4-
"version": "4.1.3",
4+
"version": "4.2.0",
55
"description": "Native Image loader for Node.js",
66
"license": "MIT",
77
"main": "index.js",

0 commit comments

Comments
 (0)