0.1.4 • Published 10 years ago
@c8/simple-promised-file v0.1.4
@c8/simple-promised-file
A small promise library with basic file functionality and promise-wrapped gm image module.
Features
- Detects and uses proper MIME type (based on file's "magic" bytes)
- Fully promised API
- ES 6 object model
- Image object wraps all graphicsmagic functionality, in a promised manner
fs-extrafile functions (also promise wrapped) available on all File objects
Installation
npm i @c8/simple-promised-file
- Image functions require either GraphicsMagic or ImageMagic
Usage
'use strict'
const PromisedFile = require('@c8/simple-promised-file')
const File = PromisedFile.File
const Image = PromisedFile.Image // extends PromisedFile.File with gm package image functionalityGet file info
Image(path.join(__dirname, '1.jpg'))
.then((img) => {
// Sync getters
console.log(img.size) // 32114 (bytes, preloaded)
console.log(img.extension) // jpg
// Async getters
img.mime.then(console.log) // image/jpeg
img.isImage.then(console.log) // true
img.depth().then(console.log) // 8
img.dimensions()
.then((dimensions) => {
console.log(`Dimensions: ${dimensions.width}x${dimensions.height}px`)
})
// etc
})
.catch(console.log)Get unique name
- generates a short URL-friendly name with a proper extension (based on file's magic bytes), uses
shortid
Image(path.join(__dirname, '1.jpg'))
.then((img) => {
return img.uniqueName
})
.then(console.log) // Sy8e7we7.jpg
.catch(console.log)Edit an image
- Image object also provides all functionality of
gmnpm package in promised manner
const blurAndResize = (img) => {
return img
.resize(257, 257)
.blur(23)
.write(path.join(__dirname, '3.jpg'))
}
Image(path.join(__dirname, '1.jpg'))
.then(blurAndResize)
.then(console.log)
.catch(console.log)License
Developed for C8 MANAGEMENT LIMITED under MIT license
0.1.4
10 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago
0.0.22
10 years ago
0.0.21
10 years ago
0.0.20
10 years ago
0.0.19
10 years ago
0.0.18
10 years ago
0.0.17
10 years ago
0.0.16
10 years ago
0.0.15
10 years ago
0.0.14
10 years ago
0.0.13
10 years ago
0.0.12
10 years ago
0.0.11
10 years ago
0.0.10
10 years ago
0.0.9
10 years ago
0.0.8
10 years ago
0.0.7
10 years ago
0.0.6
10 years ago
0.0.5
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
10 years ago
0.0.1
10 years ago