{"id":22427260,"url":"https://github.com/node-3d/image-raub","last_synced_at":"2025-08-01T10:32:01.169Z","repository":{"id":29240809,"uuid":"117735864","full_name":"node-3d/image-raub","owner":"node-3d","description":"Native Image loader for Node.js","archived":false,"fork":false,"pushed_at":"2024-11-09T13:16:46.000Z","size":8584,"stargazers_count":7,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-18T18:00:02.996Z","etag":null,"topics":["addon","cpp","decoder","freeimage","graphics","image","javascript","n-api","napi","native","node-3d","node-addon"],"latest_commit_sha":null,"homepage":"https://github.com/node-3d/node-3d","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/node-3d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-16T20:10:33.000Z","updated_at":"2024-11-09T11:33:28.000Z","dependencies_parsed_at":"2023-01-14T14:28:09.865Z","dependency_job_id":"6fa4d841-0c84-4b7b-b68f-056b9b06402b","html_url":"https://github.com/node-3d/image-raub","commit_stats":null,"previous_names":["raub/node-image"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-3d%2Fimage-raub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-3d%2Fimage-raub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-3d%2Fimage-raub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-3d%2Fimage-raub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-3d","download_url":"https://codeload.github.com/node-3d/image-raub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228364059,"owners_count":17908319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addon","cpp","decoder","freeimage","graphics","image","javascript","n-api","napi","native","node-3d","node-addon"],"created_at":"2024-12-05T20:11:18.849Z","updated_at":"2025-08-01T10:32:01.151Z","avatar_url":"https://github.com/node-3d.png","language":"JavaScript","readme":"# Image for Node.js\n\nThis is a part of [Node3D](https://github.com/node-3d) project.\n\n[![NPM](https://badge.fury.io/js/image-raub.svg)](https://badge.fury.io/js/image-raub)\n[![ESLint](https://github.com/node-3d/image-raub/actions/workflows/eslint.yml/badge.svg)](https://github.com/node-3d/image-raub/actions/workflows/eslint.yml)\n[![Test](https://github.com/node-3d/image-raub/actions/workflows/test.yml/badge.svg)](https://github.com/node-3d/image-raub/actions/workflows/test.yml)\n[![Cpplint](https://github.com/node-3d/image-raub/actions/workflows/cpplint.yml/badge.svg)](https://github.com/node-3d/image-raub/actions/workflows/cpplint.yml)\n\n```console\nnpm i -s image-raub\n```\n\nUsing [FreeImage](http://freeimage.sourceforge.net/), this addon loads images from:\n* Local file.\n* Data URI.\n* Http(s) URL.\n* Node.js Blob URL.\n* Raw RGBA pixel data.\n\nThe Image class is similar to\n[HTMLImageElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image),\nand can be used as a replacement in non-DOM environments.\n\nAdditional features:\n* `save` - saves the image to a local file.\n* `drawImage` - is similar to\n\t[drawImage](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage).\n\n\u003e Note: this **addon uses N-API**, and therefore is ABI-compatible across different\nNode.js versions. Addon binaries are precompiled and **there is no compilation**\nstep during the `npm i` command.\n\n\n## Image\n\n```js\nimport Image from 'image-raub';\nconst image = new Image('images/test.png'); // relative to CWD\nicon.on('load', () =\u003e { console.log('data', image.width, image.height, image.data); });\n```\n\nFor loaded images, `image.data` will contain a `Buffer` of `4 * width * height` bytes.\nYou can directly interact with that buffer - read or write, and then save the image\nto a file or use it any other way.\n\nWith `Image.fromPixels()` it is possible to generate new images from scratch by providing\nyour own data buffer.\n\nSee [TS declarations](/index.d.ts) for more details.\n\n\n### Set window icon\n\nCompatible with [glfw-raub](https://github.com/node-3d/glfw-raub) `window.icon` property.\n\n```js\nconst icon = new Image();\nicon.src = 'icons/logo.png';\nicon.on('load', () =\u003e { window.icon = icon; });\n```\n\n\n### Load an OpenGL texture\n\nHere `Image` is used to load a texture. The constructed object receives `src` property,\nthen the file is read and `'load'` event is emitted. After that, `image.data` is\navailable as a `Buffer`, containing the whole pixel data, and `image.width`/`image.height`\ncontain the dimensions.\n\n```js\nconst Image = require('image-raub');\nconst image = new Image();\n// Web-style onload\nimage.onload = () =\u003e {\n\tgl.bindTexture(gl.TEXTURE_2D, texture);\n\tgl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);\n\tgl.generateMipmap(gl.TEXTURE_2D);\n\tgl.bindTexture(gl.TEXTURE_2D, null);\n};\n\nimage.src = 'textures/grass.jpg';\n```\n\n\n### Make an OpenGL snapshot\n\nImage can save its current content to the filesystem. It can also load from raw\npixel values using `static fromPixels()` method.\n\n```js\nconst memSize = screen.w * screen.h * 4; // estimated number of bytes\nconst storage = { data: Buffer.allocUnsafeSlow(memSize) };\n\ngl.readPixels(\n\t0, 0,\n\tscreen.w, screen.h,\n\tgl.RGBA,\n\tgl.UNSIGNED_BYTE,\n\tstorage\n);\n\nconst img = Image.fromPixels(screen.w, screen.h, 32, storage.data);\n\nimg.save(`${Date.now()}.jpg`);\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-3d%2Fimage-raub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-3d%2Fimage-raub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-3d%2Fimage-raub/lists"}