Skip to content

Instantly share code, notes, and snippets.

@caseyWebb
Created February 10, 2018 09:08
Show Gist options
  • Save caseyWebb/e1d0ffff930ae6ead177e0948fae3d62 to your computer and use it in GitHub Desktop.
Save caseyWebb/e1d0ffff930ae6ead177e0948fae3d62 to your computer and use it in GitHub Desktop.
GhostStoragePreprocessorSqipTransform
module.exports = class GhostStoragePreprocessorSqipTransform implements IGhostStoragePreprocessorTransform {
public async save(image: Image, targetDir?: string) {
const res = sqip({ filename: image.path })
const sqipPath = image.path + '.sqip.svg'
const sqipImage = Object.assign({}, image, {
name: image.name + '.sqip.svg',
path: sqipPath,
mimetype: 'image/svg',
type: 'image/svg'
})
await new Promise((resolve, reject) =>
fs.writeFile(sqipPath, res.final_svg, (err) => err ? reject(err) : resolve()))
return [
[image, targetDir],
[sqipImage, targetDir]
] as [Image, string][]
}
public async delete(image: Image, targetDir?: string) {
return []
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment