Skip to content

Instantly share code, notes, and snippets.

@inukshuk
Last active July 13, 2023 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inukshuk/4e27b791c81d00ca9d738447b26259ab to your computer and use it in GitHub Desktop.
Save inukshuk/4e27b791c81d00ca9d738447b26259ab to your computer and use it in GitHub Desktop.
tropy-libvips-crash
sharp_libvips_binary_host=https://github.com/tropy/sharp-libvips/releases/download
sharp_install_force=true

Trying to reproduce a crash in the libvips build bundled with Tropy:

$ node -v
$ SHARP_IGNORE_GLOBAL_LIBVIPS=true npm install
$ ls node_modules/sharp/vendor/8.14.2/linux-x64/THIRD-PARTY-NOTICES.json

This is to install the sharp and libvips binary.

Then you can run the script like this:

$ npx electron . [DIRECTORY]

This will process all JPG/PNG files in [DIRECTORY]. The script loads all the files, resizes, and converts them to WebP. All this happens in memory only; nothing is saved to disk.

const { app } = require('electron')
const { readdir } = require('node:fs/promises')
const { extname, join } = require('node:path')
const { argv, cwd } = require('node:process')
const sharp = require('sharp')
let accept = ['.jpg', '.png']
let output = []
let wd = argv[2] || cwd()
console.log(`using directory ${wd}`)
;(async function () {
for (let file of await readdir(wd)) {
if (accept.includes(extname(file).toLowerCase())) {
output.push(
sharp(join(wd, file)).resize(256).webp().toBuffer()
)
}
}
console.log(`processing ${output.length} image(s)...`)
await Promise.all(output)
console.log('done')
app.quit()
})()
{
"main": "./index.js",
"dependencies": {
"electron": "^25.3.0",
"sharp": "^0.32.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment