convert-img
v1.0.1
Published
icns2png,icns2ico,png2ico,ico2png
Downloads
3
Readme
🚀 convert-img!
1. Installation
npm install convert-img
2.Usage
const imageConvert = require('convert-img')
- imageConvert
- imageConvert.pngToIco(buffer)
- imageConvert.icnsToPng(buffer)
- imageConvert.canvasToBuffer(canvas)
- imageConvert.bufferToBase64(buffer)
3. Api
3.1 pngToIco
const { pngToIco } = require('convert-img')
const { readFileSync, writeFileSync } = require('fs')
const { resolve } = require('path')
const buffer = readFileSync(resolve(__dirname, './demo.png'))
pngToIco(buffer).then(res => {
writeFileSync(resolve(__dirname, './demo.ico'), res)
})
3.2 icnsToPng
const { icnsToPng } = require('convert-img')
const { readFileSync, writeFileSync } = require('fs')
const { resolve } = require('path')
const buffer = readFileSync(resolve(__dirname, './demo.icns'))
icnsToPng(buffer).then(res => {
writeFileSync(resolve(__dirname, './demo.png'), res)
})
3.3 canvasToBuffer
const { canvasToBuffer } = require('convert-img')
const { readFileSync, writeFileSync } = require('fs')
const { resolve } = require('path')
const { createCanvas, loadImage } = require('canvas')
const canvas = createCanvas(200, 200)
const ctx = canvas.getContext('2d')
ctx.fillStyle = '#000'
ctx.fillRect(0, 0, 200, 200)
canvasToBuffer(canvas).then(res => {
fs.writeFileSync(path.resolve('./123.png'), res)
})
3.4 bufferToBase64
const { bufferToBase64 } = require('convert-img')
const { readFileSync, writeFileSync } = require('fs')
const { resolve } = require('path')
const buffer = readFileSync(resolve(__dirname, './demo.ico'))
bufferToBase64(buffer).then(base64 => {
console.log(base64)
})