npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pictoose

v0.0.6

Published

Pictures in Mongoose!

Downloads

3

Readme

Pictoose

Pictoose on NPM Pictoose downloads

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:

// Requirements
var express 	= require('express');
var multer 		= require('multer');
var mongoose 	= require('mongoose');
var Schema 		= mongoose.Schema;
// Create Express Server
var app = express();
app.use(multer({dest: './uploads/'}));
// Connect to database
mongoose.connect('mongodb://localhost/testpictoose');

// Car Schema & Model
var CarSchema = new Schema({
	model: String,
})
var Car = mongoose.model('Car', CarSchema);

...

app.listen(3000);
console.log('Listening on port 3000');

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	= require('pictoose');

Pictoose.Config('RESOURCE_STORAGE_ROOT', './public/');
Pictoose.Config('RESOURCE_STORAGE_URL', 'http://127.0.0.1:3000/public/');
Pictoose.Config('RESOURCE_MAIN_URL', 'http://127.0.0.1:3000/resources/');

CarSchema.plugin(Pictoose.Plugin, ['thumbnail','brand']);

app.use('/public',express.static('./public'));
app.get('/resources/:resid', Pictoose.RouteController);

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.post('/', function(req,res){
	var myCar = new Car(req.body);
	// Just save the image's local URI after it was uploaded and saved by, in this case, Multer
	myCar.thumbnail = req.files.thumbnail.path;
	myCar.brand = req.files.brand.path;
	myCar.save();
	res.send('ok');
});

You can also use a base64 string or a public URL to store images

app.post('/', function(req,res){
	var muCar = new Car(req.body);
	myCar.thumbnail = req.body.thumbnail; // (data:image/png;base64,...)
	myCar.brand = 'http://anotherserver.com/image.png';
	myCar.save();
	res.send('ok');
});

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