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

quickthumb-slug

v0.1.6

Published

On the fly, thumbnail creation middleware for express (with restrictions)

Downloads

12

Readme

QuickThumb-Slug

QuickThumb-Slug is an on the fly, thumbnail creation middleware for express based on the QuickThumb lib but using pre-defined sizes to avoid malicious exploitation of the library. It utilizes the popular *nix image library, ImageMagick. It allows for the automatic creation of thumbnails by adding a final slug to image filenames. It's ideal for web developers who would like to easily experiment with different size thumbnails, wihout having to worry about pre-generating an entire library.

Examples

var express = require('express'),
    app = express(),
    qt = require('quickthumb-slug');

app.use(qt.static({
    baseDir: __dirname + "/public",
    sizes: {
        square: { width: 400, height: 400, type: "crop" },
        landscape: { width: 1200, height: 600, type: "crop" },
        fitinportrait: { width: 400, height: 700, type: "resize" }
    }
}));
<img src="/public/images/red-square.gif" />

Install

npm install quickthumb-slug

ImageMagick is required for this module, so make sure it is installed.

Ubuntu

apt-get install imagemagick

Mac OS X

brew install imagemagick

Fedora/CentOS

yum install imagemagick

Usage

qt.static(options)

Middleware to replace express.static() or connect.static().

options is an object to specify customizations. It currently has the following options:

  • baseDir is the original directory where source images are located.
  • cacheDir The directory where generated images will be created. If not supplied, images will be created in [baseDir]/.cache/
  • sizes Object containing configurations for image outputs, properties are the slugs that will be used in filenames
    • width Width of resized image
    • height Height of resized image
    • type The type of imagemagick conversion to take place. There are currently only two options:
      • crop (default) Crops and zooms images to the exact size specified. Proxy to imagemagick.crop.
      • resize Resizes an image to fit within the specified dimensions, but actual dimensions may not be exactly as specified. Proxy to imagemagick.resize.
  • quality The quality to use when resizing the image. Values should be between 0 (worst quality) and 1 (best quality)

Resizing of images is directed by the image name. This is in the format [filename-without-ext]-[slug][original-ext]. E.g. red-square.gif

Resized images will be created on an as needed basis, and stored in [cacheDir]/[slug]/[dim].

If the slug is not present, the original image will be served.