Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomeraberbach/src2img
🖼️ Converts source code to high quality images.
https://github.com/tomeraberbach/src2img
beautiful converter converts-source images npm-module npm-package quality-images screenshot source
Last synced: 3 months ago
JSON representation
🖼️ Converts source code to high quality images.
- Host: GitHub
- URL: https://github.com/tomeraberbach/src2img
- Owner: TomerAberbach
- License: mit
- Created: 2018-08-13T21:57:25.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-09-24T00:09:53.000Z (3 months ago)
- Last Synced: 2024-10-14T20:23:16.901Z (3 months ago)
- Topics: beautiful, converter, converts-source, images, npm-module, npm-package, quality-images, screenshot, source
- Language: CSS
- Homepage: https://npm.im/src2img
- Size: 450 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
src2img
Converts source code to high quality images.## Install
```sh
$ npm i src2img
```## Usage
```js
import fs from 'node:fs/promises'
import { join } from 'node:path'
import src2img from 'src2img'const src = `path/to/sources`
const out = `path/to/out`const names = await fs.readdir(src)
const srcs = Promise.all(
names.map(async name => ({
name,
src: await fs.readFile(join(src, name), `utf8`),
})),
)const images = await src2img({
// Font size and unit control the size and quality of the image.
fontSize: 20,
fontSizeUnit: `pt`,
padding: 3,
// Using 'px' does not scale with font size.
paddingUnit: `vw`,
// Png or jpeg
type: `png`,
src: srcs.map(({ src }) => [
src,
// https://prismjs.com/index.html#languages-list
`javascript`,
// See https://www.npmjs.com/package/filename2prism for getting alias from
// filename.
]),
})await Promise.all(
images.map((image, i) =>
fs.writeFile(
join(out, `${srcs[i].name.replaceAll(/\.[^.]+$/gu, ``)}.png`),
image,
),
),
)
```Look at the [CLI package](https://www.npmjs.com/package/src2img-cli) if you'd
like to use this from the command line.Some rendered code:
![example](example.png)
## Related
- [filename2prism](https://www.npmjs.com/package/filename2prism)
- [src2img-cli](https://www.npmjs.com/package/src2img-cli)
- [prismjs](https://www.npmjs.com/package/prismjs)## Contributing
Stars are always welcome!
For bugs and feature requests,
[please create an issue](https://github.com/TomerAberbach/src2img/issues/new).## License
[MIT](https://github.com/TomerAberbach/src2img/blob/main/license) ©
[Tomer Aberbach](https://github.com/TomerAberbach)