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

phantomjssmith

v1.0.4

Published

PhantomJS engine for spritesmith

Downloads

1,541

Readme

phantomjssmith Build status

PhantomJS engine for spritesmith.

Requirements

This depends on having phantomjs installed on your machine. This can be done globally as listed on the PhantomJS website or locally via the node module wrapper. This module has been tested against 1.9.2 and 1.9.8.

Global installation

PhantomJS installation instructions can be found on the PhantomJS website. When phantomjssmith is running, phantomjs must be resolvable via the PATH environment variable.

http://phantomjs.org/

Local installation

A phantomjs wrapper can be install via: npm install phantomjs

https://github.com/Medium/phantomjs

When running your phantomjssmith task, it must have node_modules/.bin/ in the PATH environment variable. The easiest way to accomplish this is by using npm scripts:

// Inside our `package.json`
{
  "scripts": {
    "build": "grunt sprite"
  }
}
# Runs `grunt sprite` with `node_modules/.bin/` appended to `PATH`
npm run build

Getting Started

Install the module with: npm install phantomjssmith

// Load in our dependencies
var Phantomjssmith = require('phantomjssmith');

// Create a new engine
var phantomjssmith = new Phantomjssmith();

// Interpret some images from disk
phantomjssmith.createImages(['img1.jpg', 'img2.png'], function handleImages (err, imgs) {
  // If there was an error, throw it
  if (err) {
    throw err;
  }

  // We recieve images in the same order they were given
  imgs[0].width; // 50 (pixels)
  imgs[0].height; // 100 (pixels)

  // Create a canvas that fits our images (200px wide, 300px tall)
  var canvas = phantomjssmith.createCanvas(200, 300);

  // Add the images to our canvas (at x=0, y=0 and x=50, y=100 respectively)
  canvas.addImage(imgs[0], 0, 0);
  canvas.addImage(imgs[1], 50, 100);

  // Export canvas to image
  var resultStream = canvas['export']({format: 'png'});
  resultStream; // Readable stream outputting PNG image of the canvas
});

Documentation

This module was built to the specification for spritesmith engines.

Specification version: 2.0.0

https://github.com/twolfson/spritesmith-engine-spec/tree/2.0.0

engine.createImages(images, cb)

Our createImages methods supports the following types of images:

  • image String - Filepath to image
  • image Object - Vinyl object with null for image (uses provided filepath)

We accept but don't fully support the following types of images:

  • image Object - Vinyl object with buffer for image (ignores contents, uses provided filepath)
  • image Object - Vinyl object with stream for image (ignores contents, uses provided filepath)

canvas.export(options)

Our export method provides support for the following options:

  • options Object
    • timeout Number - Milliseconds to wait until automatically terminating PhantomJS script
      • By default, this is 10000 (10 seconds).
    • format String - Output image format to callback with. Currently, png and jpeg are available.
    • quality Number - If you are outputting a jpeg, the quality can be specified from 0 to 100.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint using npm run lint and test via npm test.

Donating

Support this project and others by twolfson via donations.

http://twolfson.com/support-me

License

Copyright (c) 2013 Todd Wolfson

Licensed under the MIT license.