* Return image as buffer
(mime = 'image/png', outOpts = {})
| 122 | * Return image as buffer |
| 123 | */ |
| 124 | async buffer(mime = 'image/png', outOpts = {}) { |
| 125 | const outputOptions = outOpts; |
| 126 | outputOptions.quality = outputOptions.quality || this.quality; |
| 127 | switch (mime.toLowerCase()) { |
| 128 | case 'image/webp': return sharp(this.image).webp(outputOptions).toBuffer(); |
| 129 | case 'image/jpeg': |
| 130 | case 'image/jpg': return sharp(this.image).jpeg(outputOptions).toBuffer(); |
| 131 | case 'image/png': |
| 132 | default: return sharp(this.image).png(outputOptions).toBuffer(); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | module.exports = Image; |