# image-proxy

> A simple image proxy optimized for headshots

Latest version **0.0.7** (published 2015-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install image-proxy
pnpm add image-proxy
yarn add image-proxy
bun add image-proxy
```

Provides the command `image-proxy`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2015-09-21 |
| First published | 2014-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.6.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 59 |
| Author | James McKinney |
| Maintainers | jpmckinney |
| Keywords | image, proxy |

## Links

- npm: https://www.npmjs.com/package/image-proxy
- Repository: https://github.com/jpmckinney/image-proxy
- Issues: https://github.com/jpmckinney/image-proxy/issues
- npm.io page: https://npm.io/package/image-proxy

## Dependencies (3)

- [gm](https://npm.io/package/gm.md) >=1.2.0
- [mime](https://npm.io/package/mime.md) >=1.1.0
- [express](https://npm.io/package/express.md) >=3

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2015-09-21
- 0.0.6 — 2015-04-16
- 0.0.4 — 2015-03-11
- 0.0.3 — 2015-01-16
- 0.0.2 — 2014-10-06

## README

# Image Proxy

[![NPM version](https://badge.fury.io/js/image-proxy.svg)](https://badge.fury.io/js/image-proxy)
[![Build Status](https://secure.travis-ci.org/jpmckinney/image-proxy.png)](https://travis-ci.org/jpmckinney/image-proxy)
[![Dependency Status](https://david-dm.org/jpmckinney/image-proxy.svg)](https://david-dm.org/jpmckinney/image-proxy)
[![Coverage Status](https://coveralls.io/repos/jpmckinney/image-proxy/badge.png)](https://coveralls.io/r/jpmckinney/image-proxy)

A simple Express app for proxying and manipulating images, specifically headshots.

The code is just over 100 lines, making it easy to tailor to your needs.

## Getting Started

    npm install
    npm start
    curl -I http://localhost:5000/http%3A%2F%2F1.gravatar.com%2Favatar%2F60f641dfbb4215f1f6d6c059eebf1848/240/80.jpg

The URL structure is `/:url/:width/:height.:extension?`. The `:url` parameter must be escaped/encoded. If the remote image's width or height is greater than the given `:width` or `:height`, it will be resized, maintaining aspect ratio, and cropped. If smaller, it will be padded with white pixels. If an optional `:extension` parameter is provided, the image will be transcoded to the corresponding file format. The equivalent ImageMagick command for the example URL above is:

    convert input.jpg -thumbnail 240x80^> -gravity center -extent 240x80 output.jpg

The `Cache-Control` header sets a `max-age` of one year.

## Features

Image proxy:

* Supports HTTP and HTTPS
* Follows 301 and 302 redirects
* Sets a maximum timeout for the remote server
* Handles complex MIME types like `image/jpeg; charset=utf-8`
* Optional whitelisting using regular expressions

Image manipulation:

* Accepts a custom width and height, up to 1000x1000
* Resizes, centers and crops the image
* Optionally transcodes to another file format

HTTP server:

* No query string parameters (preferred by CloudFront)
* Adds a Cache-Control header

If you need more features, see [node-imageable](https://github.com/sdepold/node-imageable) and [node-imageable-server](https://github.com/dawanda/node-imageable-server).

### Environment variables

* `DELAY`: The timeout delay in milliseconds, after which the proxy will respond with a HTTP 504 Gateway Timeout server error. Default: `5000`
* `WHITELIST`: A comma-separated list of domains to whitelist, e.g. `.gov,facebook.com`, which will be transformed into the regular expressions `/\.gov$/` and `/facebook\.com$/`.
* `PORT`: If running the server, changes the port on which it listens. Default: `5000`

## Deployment

### Heroku

    git clone https://github.com/jpmckinney/image-proxy.git
    heroku create
    heroku config:set NODE_ENV=production
    git push heroku master
    heroku apps:open

### AWS CloudFront

Create a distribution and set the "Origin Domain Name" to the domain name of your Heroku app.

## Testing

    npm test

## Acknowledgements

This project is inspired by [node-connect-image-proxy](https://github.com/mysociety/node-connect-image-proxy).

Copyright (c) 2013 James McKinney, released under the MIT license

---
_Source: https://npm.io/package/image-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
