YUBIGEN
Node Thumbnail generation without limits
Prerequisites
Please refer to the operating system-specific instructions on installing the following before using YUBIGEN.
- both
graphicsmagick
andimagemagick
npm
andnode
gm
package fornpm
. Ifnpm
has been installed, simply runnpm install gm
.aws-sdk
package fornpm
, installed at the application level, but only if putting objects to AWS S3
Description of Implementation
YUBIGEN makes use of the resize
and crop
functions found in gm
to resize and crop images according to specified parameters, respectively passed into the resizeParams
and cropParams
fields in the second parameter object in arrays. The third parameter is passed a callback which handles the resulting buffer in the specified manner.
YUBIGEN also has a way to predict the format of the input, as well as a function to output to a specified file and to upload to an AWS S3 Bucket. Format-specific functions have been made available as well.
Methods
yubigen.fromUrl(url, paramObj, callback)
Manipulates image given URL
yubigen.fromFile(path, paramObj, callback)
Manipulates image from file given path
yubigen.fromBuffer(buffer, paramObj, callback)
Manipulates image from a buffer given path
yubigen.predict(input, paramObj, callback)
Predicts format (string or buffer) of the given input
yubigen.outToFile(outFile, input, paramObj, callback)
Outputs to file as specified from input format prediction
yubigen.s3Put(config, bucket, path, input, paramObj, callback)
With specified credentials (default if config
is null
), outputs to specified S3 Bucket as specified from
input format prediction (requires external install of aws-sdk
package)
Parameter Object Keys
resizeParams
: resize parameters as specified byresize
in a one-dimensional arraycropParams
: crop parameters as specified bycrop
in a one-dimensional arraytextParams
: an array of text parameter objects. Text parameter object schema is as follows.format
: file formatimageMagick
: ImageMagick enabled if true
Callback
result
: resulting buffererr
: error if any
Usage
const yubigen = fs = AWS = ; // for demonstration purposesvar params = resizeParams: 100 // resize parameters as specified by gm resize cropParams: 5050200 // crop parameters as specified by gm crop format: "JPEG" // file format imageMagick: false // ImageMagick not enabled textParams: // Text parameter object #1: color: "#5940de" fontSize: "24pt" drawParams: 0 0 "CENSORED" "Center" // text draw parameters as specified by gm drawText color: "#000000" fontSize: "12pt" drawParams: 0 0 "VOID" "Center" { // write to file callback fs;} { // callback to upload to S3 Bucket, for demonstration purposes var args = Bucket: BUCKET_NAME Key: KEY_NAME Body: result var s3 = ; s3;}; // From URLyubigen; // From fileyubigen; // From bufferfs; // Export from URL to fileyubigen; // Put Object to S3 bucket `my-bucket` with default AWS credentialsfs;
Author
- Derek Chan
Contributors
- Pull requests and issues are welcome! Feature requests will be considered on a case-by-case basis.