All Projects â†’ thatisuday â†’ npm-sharper

thatisuday / npm-sharper

Licence: Apache-2.0 license
📷 Automatic image processor middleware built on top of sharp and multer for express.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to npm-sharper

Hide-Image-in-Image
Code that lets you hide an image in another image and decode it again without information loss
Stars: ✭ 21 (+23.53%)
Mutual labels:  image-manipulation
ImagerJs
A JavaScript library for uploading images using drag & drop. Crop, rotate, resize, or shrink your image before uploading.
Stars: ✭ 101 (+494.12%)
Mutual labels:  image-manipulation
imei
IMEI - ImageMagick Easy Install
Stars: ✭ 126 (+641.18%)
Mutual labels:  image-manipulation
imagekit-python
ImageKit.io Python SDK
Stars: ✭ 27 (+58.82%)
Mutual labels:  image-manipulation
querymen
Querystring parser middleware for MongoDB, Express and Nodejs (MEN)
Stars: ✭ 128 (+652.94%)
Mutual labels:  express-middleware
gobarber-api-gostack11
API GoBarber / NodeJS / Express / Typescript / SOLID
Stars: ✭ 39 (+129.41%)
Mutual labels:  multer
2dimagefilter
A collection of image filters, some especially suited to scale-up low res computer graphics.
Stars: ✭ 32 (+88.24%)
Mutual labels:  image-manipulation
imaditor
Image Editor with a UI creatief with ImGui
Stars: ✭ 24 (+41.18%)
Mutual labels:  image-manipulation
grafx2
Mirror of GrafX2. Official repo is on gitlab.
Stars: ✭ 108 (+535.29%)
Mutual labels:  image-manipulation
moesif-nodejs
Moesif Nodejs Middleware Library (formerly Moesif-Express)
Stars: ✭ 36 (+111.76%)
Mutual labels:  express-middleware
sic
🦜 Accessible image processing and conversion from the terminal. Front-end for image-rs/image.
Stars: ✭ 96 (+464.71%)
Mutual labels:  image-manipulation
Coursera-Clone
Coursera clone
Stars: ✭ 48 (+182.35%)
Mutual labels:  multer
AODA
Official implementation of "Adversarial Open Domain Adaptation for Sketch-to-Photo Synthesis"(WACV 2022/CVPRW 2021)
Stars: ✭ 44 (+158.82%)
Mutual labels:  image-manipulation
image-upload-app
A simple image upload application using React and Node, which explores multiple ways to upload an image including using multer as a middleware, a CDN system and converting an image to a string and storing it.
Stars: ✭ 35 (+105.88%)
Mutual labels:  multer
imagekit-angular
Angular SDK for ImageKit.io client side file upload and URL generation
Stars: ✭ 16 (-5.88%)
Mutual labels:  image-manipulation
picedit
simple set of functions and cli for image manipulation
Stars: ✭ 12 (-29.41%)
Mutual labels:  image-manipulation
auto-cloudinary
Super simple Cloudinary auto-upload implementation for WordPress.
Stars: ✭ 34 (+100%)
Mutual labels:  image-manipulation
ZaneAPI
Image manipulation API for the layman.
Stars: ✭ 12 (-29.41%)
Mutual labels:  image-manipulation
node-js-file-upload
NodeJS File upload with GridFS and Multer
Stars: ✭ 26 (+52.94%)
Mutual labels:  multer
express-graphql
Create a GraphQL HTTP server with Express.
Stars: ✭ 6,301 (+36964.71%)
Mutual labels:  express-middleware

sharper Build Status npm downloads npm version npm dependencies

Automatic image processor built on top of sharp and multer for express.


How does it work?

When you are working on a website which needs to create multiple size copies of a single image uploaded by user, resize | crop | process and finally upload in a dynamic directory based on current date or time, then this module will save your entire lifetime.

Basically, this module provide an express middleware that do all above things at once. If something goes wrong, you can catch it in error middleware. You need to provide few options that will tell sharper about location of upload, dynamic date format for upload folder to be created, accepted image types, upload size limits, output format, and output sizes with prefixes etc.

This module is based on sharp node-js module for image processing. It's the fastest module there is and based on libvips library.


Install

npm install --save sharper

Configure

set options

const sharper = require('sharper');
var Sharper = sharper({
    field : 'file',
    location : '/var/www/uploads/',
    dirFormat : 'yyyy/mmm/d',
    maxFileSize: '20mb',
    fileNameLen : 50,
    accept : ['jpeg', 'jpg', 'png'],
    output : 'jpg',
    sizes : [
        {suffix : 'xlg', width : 1200, height : 1200},
        {suffix : 'lg', width : 800, height : 800},
        {suffix : 'md', width : 500, height : 500},
        {suffix : 'sm', width : 300, height : 300},
        {suffix : 'xs', width : 100, height : 100},
    ]
});

add middleware

app.post('/upload', Sharper, function(err, req, res, next){
    console.log(err);
    res.status(500).send('upload failed...');
}, function(req, res){
    console.log(res.sharper);
    res.send('upload successful...');
});

Options

var Sharper = sharper(options);

sharper options

option default role
field 'file' input file field in multipart form data. ex. <input type="file" name="file"/>
location '/var/www/html/' upload directory.
dirFormat 'yyyy/mmm/d' date pattern to follow for folder creation for image storage. Explore formats at [node-format module](https://github.com/felixge/node-dateformat#mask-options)
fileNameLen 50 length of the output image filename.
maxFileSize '10mb' maximum size of input/upload file to accept.
accept ['png','jpeg','jpg'] array of file types/extensions to accept.
output 'jpg' type of output file to produce. valid options : jpg, png, gif, webp, tiff, bmp
sizes [{suffix : 'lg', width : 500, height:500}, ...] Array of size specification object for output images (with filename suffix to produce output-name.lg.jpg format).

sharp options

Please visit this sharp sharp for detailed overview of specific option.

option default role
resize true resize images as per their sizes mentioned in options.sizes
crop false crop images as per their sizes mentioned in options.sizes
background {r: 200 , g:200, b:200, a:1} set the background for the embed, flatten and extend operations.
embed false embed on canvas
max false set maximum output dimension
min false set minimum output dimension
withoutEnlargement false do not enlarge small images
ignoreAspectRatio false ignore aspect ration while resizing images
extract false extract specific part of image
trim false Trim boring pixels from all edges
flatten false Merge alpha transparency channel, if any, with background.
extend false Extends/pads the edges of the image with background.
negate false Produces the negative of the image.
rotate false Rotate the output image by either an explicit angle
flip false Flip the image about the vertical Y axis.
flop false Flop the image about the horizontal X axis.
blur false Mild blur of the output image
sharpen false Mild sharpen of the output image
gamma false Apply a gamma correction.
grayscale or greyscale false Convert to 8-bit greyscale; 256 shades of grey.
normalize or normalise false Enhance output image contrast by stretching its luminance to cover the full dynamic range.
progressive false Use progressive (interlace) scan for JPEG and PNG output.
quality false The output quality to use for lossy JPEG, WebP and TIFF output formats. The default quality is 80.

Errors

You can catch errors in error middleware as shown previously. err object includes (but not limited to) following error codes (key code).

code role
FILE_TYPE_UNSUPPORTED Input file type is not acceptable to process. check accept option.
LIMIT_FILE_SIZE Input file size is too large. Check maxFileSize option.

Success

Upon successful upload, sharper will add sharper object in res response object. It will have following properties.

key role
dir dir that was created for storing process image.
destination absolute path of storage destination.
filename name of the image files created using sharper.

Test

  • npm install
  • npm install -g mocha
  • npm test

in practice

  • npm install -g bower
  • bower install
  • Open terminal and run node test-server.js in demo folder of this module.
  • Open your browser and go to http://localhost:8800.
  • Upload a photo by clicking on dropzone.
  • If upload sucessfully completes, check upload directory /var/www/html.
  • If error occurs, check your terminal.

If you are facing node-gyp related error, go to node_modules/sharper/node_modules/sharp and use cmd command node-gyp rebuild. Make sure you have node-gyp installed or use npm install -g node-gyp

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].