JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 30
  • Score
    100M100P100Q44337F
  • License ISC

Node Thumbnail generation without limits

Package Exports

  • yubigen

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (yubigen) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

YUBIGEN

Node Thumbnail generation without limits

Prerequisites

Please refer to the operating system-specific instructions on installing the following before using YUBIGEN.

  • both graphicsmagick and imagemagick
  • npm and node
  • gm package for npm. If npm has been installed, simply run npm install gm.

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.

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

Usage

const yubigen = require('yubigen'), fs = require('fs'),
  AWS = require('aws-sdk'); // for demonstration purposes
var params = {
  resizeParams: [100], // resize parameters as specified by gm resize
  cropParams: [50,50,20,0], // crop parameters as specified by gm crop
  format: "JPEG", // file format
  imageMagick: false // ImageMagick enabled
}, writeFile = (result, err) => { // write to file callback
  fs.writeFile("bruh.png", result, (error) => {
    if (error) console.log(error);
  });
}, s3_upload = (result, err) => { // callback to upload to S3 Bucket, for demonstration purposes
  var args = {
    Bucket: BUCKET_NAME
    Key: KEY_NAME,
    Body: result
  }, var s3 = new AWS.S3();
  s3.putObject(args, function(error) {
    if (error) console.log(error);
  });
};

// From URL
yubigen.fromUrl("https://ktuh.org/img/ktuh-fm-logo.png", params, writeFile);

// From file
yubigen.fromFile("bruh.png", params, s3_upload);

// From buffer
fs.readFile('alpha.jpg', function(error, data) {
  yubigen.fromBuffer(data, { resizeParams: [90], cropParams: [50,50,20,0],
  format: "PNG"}, (result, err) => {
    fs.writeFile("gamma.png", result, (error) => {
      if (error) console.log(error);
    });
  });
});

Contributors

  • Derek Chan