npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yubigen

v1.1.0

Published

Node Thumbnail generation without limits

Downloads

5

Readme

YUBIGEN

Node Thumbnail generation without limits

NPM version npm Build Status

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.
  • aws-sdk package for npm, 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 by resize in a one-dimensional array
  • cropParams: crop parameters as specified by crop in a one-dimensional array
  • textParams: an array of text parameter objects. Text parameter object schema is as follows.
    • fontName: name of font to use, passed into font
    • fontSize: text font size, passed into fontSize
    • color: text fill color, passed into fill
    • drawParams: text draw parameters as specified by drawText in a one-dimensional array
  • format: file format
  • imageMagick: ImageMagick enabled if true

Callback

  • result: resulting buffer
  • err: error if any

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 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"]
    }
  ]
}, 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, params, (result, err) => {
    fs.writeFile("gamma.png", result, (error) => {
      if (error) console.log(error);
    });
  });
});

// Export from URL to file
yubigen.outToFile('logo.png', "https://ktuh.org/img/ktuh-fm-logo.png", params,
(result, err) => {
  if (error) console.log(error);
  else console.log(result);
});

// Put Object to S3 bucket `my-bucket` with default AWS credentials
fs.readFile('test/images/alpha.jpg', function(error, data) {
  yubigen.s3Put(null, "my-bucket", "alpha.png", data, params,
  (result, err) => {
    if (error) console.log(error);
    else if (result) console.log("Upload success!");
  });
});

Author

  • Derek Chan

Contributors

  • Pull requests and issues are welcome! Feature requests will be considered on a case-by-case basis.