Pictoose is a Mongoose plugin made for make image storage (and video!) easiest possible
Now with image resizing
How to use it
Lets supose that you actually have this code:
// Requirementsvar express = ;var multer = ;var mongoose = ;var Schema = mongooseSchema;// Create Express Servervar app = ;app;// Connect to databasemongoose;// Car Schema & Modelvar CarSchema =model: Stringvar Car = mongoose;...app;console;
To use Pictoose all you need to do is require de module, configure it and include the plugin to a Schema by this way:
var Pictoose = ;Pictoose;Pictoose;Pictoose;CarSchema;app;app;
Now every image will be stored in the 'public' folder (RESOURCE_STORAGE_ROOT), Pictoose will construct the URLs using the RESOURCE_STORAGE_URL to return de images.
Also you need to specify a RESOURCE_MAIN_URL used to handle broken links, resizing, etc. and add it to your Express routing.
And finally, will create the fields 'thumbnail' and 'brand', so to save an image with Pictoose al you need to do is this:
You can also use a base64 string or a public URL to store images
When Pictoose receives a new image/video in base64/filepath, it will validate the file.
Supported file formats:
If Pictoose receives a public URL will not validate anything and will directly store the URL
Image resizing is simple, if we have the following URL generated and stored by Pictoose:
And we add this query:
Will resize the image, store it in his new size, and return the public URL of the new image, the next time we query the same resize options, the image will be already resized and stored.
Resize options are: widthxheight(fill|afit|afil)