Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vinc/rehost
Express middleware to rehost and resize images
https://github.com/vinc/rehost
express middleware rehost resize
Last synced: 14 days ago
JSON representation
Express middleware to rehost and resize images
- Host: GitHub
- URL: https://github.com/vinc/rehost
- Owner: vinc
- License: mit
- Created: 2017-03-11T13:59:43.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T10:12:03.000Z (almost 5 years ago)
- Last Synced: 2024-11-20T00:11:59.663Z (about 1 month ago)
- Topics: express, middleware, rehost, resize
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/rehost
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# README
Express middleware to rehost and resize images
## Install
$ npm install rehost
## Usage
```javascript
var express = require('express');
var rehost = require('rehost');
var app = express();
app.use('/:rehost.:format', rehost());
app.listen(3000);
```Requesting the following URL on the server:
http://localhost:3000/aHR0cDovL2V4YW1wbGUuY29tL2ltYWdlLnBuZw.jpg?resize=500x500
Will fetch, resize and convert the image at:
http://example.com/image.png
The source URL is encoded using "Base 64 Encoding with URL and Filename Safe
Alphabet" from [RFC 4648][1] without padding.Example in JavaScript:
```javascript
var base64 = require('base64-url');
var url = 'http://example.com/image.jpg'
var enc = base64.encode(url);
```Example in Ruby:
```ruby
require 'base64'
url = 'http://example.com/image.jpg'
enc = Base64.urlsafe_encode64(url, padding: false)
```### Parameters
The `resize` parameter is a subset of [ImageMagick geometry][2]:
`x{!}`.The `format` parameter to convert the image can be `jpg` or `png`.
The `rehost`, `resize` and `format` parameters can be in the query string or
the path of the request. They can also be defined in an optional `options`
object passed to the middleware function.[1]: https://tools.ietf.org/html/rfc4648#section-5
[2]: http://www.imagemagick.org/Magick++/Geometry.html### Caching
No caching is done on the server so it should be running behind a CDN.
## License
Copyright (c) 2017 Vincent Ollivier. Released under MIT.