resizin
Core package for uploading images and building url of images from Resizin.
Table of contents
Installation
Using npm:
npm i -s resizin
Using yarn:
yarn add resizin
Quick start
import { buildUrlFactory, uploadFactory } from 'resizin';
import config from '../config';
// Uploading image
const upload = uploadFactory({
apiKey: config.RESIZIN_API_KEY,
})
upload(files[0]);
// Building image url
const buildUrl = buildUrlFactory({
bucket: 'ackee',
});
const imageUrl = buildUrl('walle', {
width: 250,
});
API
buildUrlFactory
buildUrlFactory(options: ClientOptions): function(imageId, modifiers)
interface ClientOptions {
serverUrl?: string;
bucket: string;
}
The factory returns buildUrl(imageId: string, modifiers: object)
function.
The function returns url of an image that is available at image server adjusted according to a provided modifiers.
import { buildUrl } from 'resizin';
const buildUrl = buildUrlFactory({
serverUrl: 'https://img.resizin.com',
bucket: 'ackee',
});
const imageUrl = buildUrl(
'walle',
{
width: 250,
filter: 'sharpen',
backgroundColor: '00bcd4',
border: [10, 60, 10, 10]
}
);
const secondImageUrl = buildUrl('walle', { filter: 'negative', rotate: 180 });
Here's how result images look like
imageUrl
secondImageUrl
For a complete list of usable modifiers look at the standalone modifiers section.
Usage tips
-
You can omit
serverUrl
option when it'shttps://img.resizin.com
as it is a default valueimport { buildUrlFactory } from 'resizin'; const buildUrl = buildUrlFactory({ bucket: 'ackee' });
-
buildUrlFactory
is also default export from the package sou you can choose from two ways of importing itimport { buildUrlFactory } from 'resizin'; // is the same as a import buildUrlFactory from 'resizin';
That gives you an ability to name the factory whatever you like at the phase of importing it.