{"id":20827242,"url":"https://github.com/ccnokes/electron-named-image","last_synced_at":"2025-08-01T07:10:32.259Z","repository":{"id":57221741,"uuid":"91647576","full_name":"ccnokes/electron-named-image","owner":"ccnokes","description":"Native node.js addon that returns built-in macOS icons as a PNG buffer. It's cool when used with Electron's TouchBar or Menu APIs.","archived":false,"fork":false,"pushed_at":"2018-04-08T03:27:49.000Z","size":149,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T14:43:50.101Z","etag":null,"topics":["electron","macos"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ccnokes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-18T04:10:00.000Z","updated_at":"2024-08-12T19:10:00.000Z","dependencies_parsed_at":"2022-08-29T04:10:07.449Z","dependency_job_id":null,"html_url":"https://github.com/ccnokes/electron-named-image","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccnokes%2Felectron-named-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccnokes%2Felectron-named-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccnokes%2Felectron-named-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccnokes%2Felectron-named-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccnokes","download_url":"https://codeload.github.com/ccnokes/electron-named-image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252683564,"owners_count":21788064,"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":["electron","macos"],"created_at":"2024-11-17T23:11:33.363Z","updated_at":"2025-05-07T21:03:14.370Z","avatar_url":"https://github.com/ccnokes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# This is deprecated because this functionality is now in Electron core. \nSee https://github.com/electron/electron/pull/10727\n\n---\n\n# electron-named-image\nNative node.js addon that returns Objective-C `[NSImage imageNamed]` calls as a PNG buffer, which simplifies using default macOS images in Electron apps.\n\n## Install\n\n```\nnpm install electron-named-image\n```\n\nWhile macOS is currently the only supported platform, this module can be safely installed and used on non-macOS platforms. (No need to wrap your `require` in a conditional statement or other work-arounds).\n\n## What? Why?\n\nThis lets you use default macOS images/icons with little effort. So you can set up your TouchBar to look like this:\n\n\n![](https://github.com/ccnokes/electron-named-image/blob/master/example-images/Screen%20Shot%202017-05-29%20at%2012.51.49%20PM.png)\n\n(Note the macOS TouchBar icons in there in between the defaults)\n\n\n\n...or your menu to look like this:\n\n![](https://github.com/ccnokes/electron-named-image/blob/master/example-images/Screen%20Shot%202017-05-29%20at%2012.47.21%20PM.png)\n\n(Note the icons on the menu items)\n\n...without having to manually gather together a bunch of image files. These images/icons are included as a part of macOS and available to Objective-C and Swift via the `NSImage` API. This module allows you to use it via Javascript.\n\n## Sample usage:\n\n```javascript\nnew TouchBarButton({\n  icon: nativeImage.createFromBuffer(\n    namedImage.getImageNamed('NSTouchBarRefreshTemplate')\n  )\n})\n```\n\n```javascript\nMenu.setApplicationMenu(Menu.buildFromTemplate([\n  {\n    label: 'My App',\n    submenu: [\n      { \n        label: 'Empty Trash',\n        icon: nativeImage.createFromBuffer(\n          namedImage.getImageNamed('NSTrashFull')\n        ).resize({ width: 20 })\n      }\n    ]\n  }\n]));\n```\n\nFor all possible \"named images\" on macOS, [see this](http://hetima.github.io/fucking_nsimage_syntax/).\n\nIf you specify an invalid named image or are using it on a macOS version that pre-dates `NSTouchBar*` icons, you'll get back an empty buffer. For example:\n\n```javascript\nnamedImage.getImageNamed('invalid').length // =\u003e 0\nnamedImage.getImageNamed('NSTrashFull').length // =\u003e 9166\n```\n\nThe empty buffer will work as expected with Electron's `nativeImage` module, you just won't have any actual image.\n\nAll of the `NSTouchBar*` named images have been outputted as PNGs to the `images` folder which you can use as well just by manually saving and importing them into your app.\n\n## Compiling for use in an Electron app\nSee [https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md] for the easy, right way. Or you can also `npm install -g node-gyp` and then run the same `compile-for-electron` script I have in the package.json in the root of this module's folder.\n\n\nInspired by https://github.com/electron/electron/issues/9414\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccnokes%2Felectron-named-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccnokes%2Felectron-named-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccnokes%2Felectron-named-image/lists"}