Pictoose
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:
app;
You can also use a base64 string or a public URL to store images
app;
When Pictoose receives a new image/video in base64/filepath, it will validate the file.
Supported file formats:
- png
- jpg
- jpeg
- gif
- png
- bmp
- webp
- mp4
- avi
- mov
- mpeg
If Pictoose receives a public URL will not validate anything and will directly store the URL
That's all!
Image Resizing
Image resizing is simple, if we have the following URL generated and stored by Pictoose:
http://127.0.0.1:3000/resources/d8fbd233ac9deee7046841f02fb313ed.jpg
And we add this query:
http://127.0.0.1:3000/resources/d8fbd233ac9deee7046841f02fb313ed.jpg?resize=200x300afit
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)
License
MIT