@webhandle/request-image-resizer

1.0.0 • Public • Published

Request Image Resizer

Written for the Webhandle framework, (although usable for any Express project), this code watches for requests for images, determines if the query requests that the image be resized, resizes the image if needed, and then changes the express request to point to the resized image.

Install

npm install @webhandle/request-image-resizer

Usage

import RequestImageResizer from "@webhandle/request-image-resizer"
import webhandle from 'webhandle'

let resizer = new RequestImageResizer({
	servingSink: webhandle.sinks.project
})

webhandle.routers.preStatic.use(resizer.getHandlerFunction())

To construct a URL which triggers the code, use something like this:

http://localhost:3000/img/4cats.jpg?webhandle-image-resizer&maxHeight=268px

or

http://localhost:3000/img/4cats.jpg?webhandle-image-resizer&maxWidth=268px

Options

	/**
	 * @param {object} [options] 
	 * @param {string} [options.queryTag] a string which must be in the query string of the URL to indicate that
	 * that this request should be processed.
	 * @param {FileSink} [options.servingSink] The FileSink which contains the images to be served/resized
	 * @param {string} [options.originPrefix] The path within the sink which is the root of the file servering tree ("public")
	 * @param {string} [options.cachePrefix] The path within the originPrefix directory where the resized images are put ("img-cache")
	 * @param {boolean} [options.generate] Set to false to keep images from being generated
	 */

Readme

Keywords

none

Package Sidebar

Install

npm i @webhandle/request-image-resizer

Weekly Downloads

2

Version

1.0.0

License

ISC

Unpacked Size

8.16 kB

Total Files

5

Last publish

Collaborators

  • dankolz