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

jpegtransmith

v0.1.2

Published

jpegtran engine for spritesmith

Downloads

5

Readme

jpegtransmith

jpegtran engine for spritesmith. It uses jpegtran and gm for lossless crop'n'drop, which allows it to improve the quality on the edges in each image of the sprite.

Getting Started

Install the module with: npm install jpegtransmith

var
  spritesmith = require('spritesmith'), // or if using grunt-spritesmith: require('grunt-spritesmith/node_modules/spritesmith/src/smith.js')
  jpegtransmith = require('jpegtransmith');

  spritesmith.addEngine('jpegtransmith', jpegtransmith);

  spritesmith({src: sprites, engine: 'jpegtransmith'}, function handleResult (err, result) {
    result.image; // Binary string representation of image
    result.coordinates; // Object mapping filename to {x, y, width, height} of image
    result.properties; // Object with metadata about spritesheet {width, height}, see Requirements for possible disparities
  });

NOTE: This module is slow, mainly because of jpegtran usage. If you have any suggestion in how to improve speed, open an issue.

Requirements

jpegtransmith depends on:

  • jpegtran, the download link is at the bottom in section 3, the binary must be globally accessible
  • gm which depends on Graphics Magick.

For this to work, we use a virtual grid of 8x8 blocks. It requires your images dimensions to be multiple of 8, for the jpegtran -drop command to work correctly. If you specify a padding in spritesmith, it must also be a multiple of 8. If your images don't fit this description they will be used as-is but the individual images may be cropped and their generated dimensions will be off by a few pixels (since they will be readjusted to align to 8x8), to correct the second problem you can use this (on grunt-spritesmith):

  var imdDataCache = {};

  // Save the real img data for later use
  jpegtransmith.imageDataMutator = function(imgData){
    imgDataCache[imgData.file] = imgData;
  }

  // grunt config
  // Restore the original width and height
  sprite: {
    my_sprite: {
      // ...
      cssVarMap: function(sprite){
        var imgData = imgDataCache[sprite.source_image];
        if(imgData){
          sprite.width = imgData.realWidth;
          sprite.height = imgData.realHeight;
        }
      }
    }
  }

Alternatively, you can use ImageMagick which is implicitly discovered if gm is not installed. http://www.imagemagick.org/script/index.php

Documentation

This module was built to the specification for all spritesmith modules.

NOTE: This module fails most of the test in spritesmith-engine-test because it only works for JPEG images and it modifies the final size of the sprite by adjusting each image to a 8x8 grid.

https://github.com/twolfson/spritesmith-engine-test

canvas['export'](options, cb)

These are options specific jpegtranmsith

  • options Object
    • quality Number: 92 - Quality of each image on a scale from 0 to 100 (All image edges will be in original quality)
    • improvedEdgeSize Number: 8 - The number of pixels from the edge inwards to keep intact for the individual images in the final sprite
    • bg String: black - The background color used on the sprite
    • samplingFactor String: 1x1,1x1,1x1

Contributing

Take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

License

MIT Copyright (c) 2014 Luis Hernandez