GithubHelp home page GithubHelp logo

bob6664569 / quickthumb-slug Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zivester/node-quickthumb

0.0 2.0 0.0 126 KB

On the fly, thumbnail creation middleware for express.

Home Page: https://www.npmjs.com/package/quickthumb-slug

License: MIT License

JavaScript 100.00%
image-processing javascript nodejs thumbnails

quickthumb-slug's Introduction

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

import express from 'express';
import quickThumbs from 'quickthumb-slug';

const app = express();

app.use(quickThumbs.static({
    baseDir: process.cwd() + "/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="/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.

quickthumb-slug's People

Contributors

bob6664569 avatar tap-chris avatar zivester avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.