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

@magento/express-sharp

v3.1.0

Published

Real-time image processing for your express application

Downloads

187

Readme

express-sharp

express-sharp adds real-time image processing routes to your express application. Images are processed with sharp, a fast Node.js module for resizing images.

Build Status Test Coverage

Installation

$ yarn add express-sharp
$ npm install express-sharp --save

See sharp installation for additional installation instructions.

Usage

Example app.js:

'use strict'

const express = require('express')
const app = express()
const scale = require('express-sharp')

const options = {baseHost: 'mybasehost.com'}
app.use('/my-scale', scale(options))

app.listen(3000)

Render http://mybasehost.com/image.jpg with 400x400 pixels:

GET /my-scale/image.jpg?width=400 HTTP/1.1
Host: localhost:3000

--> invokes in background:
  GET image.jpg HTTP/1.1
  Host: mybasehost.com

Same as above, but with 80% quality, webp image type and with progressive enabled:

GET /my-scale/image.jpg?format=webp&quality=80&progressive=true HTTP/1.1
Host: localhost:3000

Options

const scale = require('express-sharp')
app.use('/some-path', scale(options))

Supported options:

baseHost

Specify the HTTP base host from which images will be requested.

cropMaxSize

The maximum length in pixels (width or height) a cropped Image is allowed to have. Note: if this value is too high an attacker could use this to slow down your server. Default is 2000

cors

Specify CORS options as described in cors docs. Example:

app.use('/some-path', scale({
  cors: {
    origin: 'http://example.com'
  }
}))

If not specified, a Access-Control-Allow-Origin: * header is being sent.

Path and query params

format

Output image format.

Default: webp if supported else the output format of the requested image.

Valid values: every valid sharp output format string, i.e. jpeg, gif, webp or raw.

progressive

only available for jpeg and png formats:

See sharp docs for jpeg.

See sharp docs for png.

Use &progressive=true to enable progressive scan.

quality

See sharp docs.

quality is a Number between 1 and 100.

crop

See sharp docs.

Use &crop=true to enable the sharp cropping feature.

Default is `false.

Note: Both width and height params are neccessary for crop to work.

gravity

See sharp docs.

When the crop option is activated you can specify the gravity of the cropping.

Possible attributes of the optional gravity are north, northeast, east, southeast, south, southwest, west, northwest, center and centre.

Default is center;

License

MIT