All Projects → olebedev → Cdn

olebedev / Cdn

Licence: mit
Content Delivery Network on the top of MongoDb GridFs with on-the-fly image crop/resize

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Cdn

Docker Nginx Image Proxy
on the fly image cropping with gravity, resize and compression microservice
Stars: ✭ 79 (-32.48%)
Mutual labels:  crop, resize, cdn
pdf-thumbnail
npm package to create the preview of a pdf file
Stars: ✭ 23 (-80.34%)
Mutual labels:  resize, crop
ipx
High performance, secure and easy to use image proxy based on Sharp and libvips.
Stars: ✭ 683 (+483.76%)
Mutual labels:  resize, cdn
node-imaginary
Minimalist node.js command-line & programmatic API client for imaginary
Stars: ✭ 94 (-19.66%)
Mutual labels:  resize, crop
image-php
很多PHP框架竟然没有图片设定宽高居中剪裁的功能,比如CodeIgniter,所以我自己封装了一个图片处理类:可设定宽高居中剪裁、设定宽高等比缩放、创建缩略图
Stars: ✭ 17 (-85.47%)
Mutual labels:  resize, crop
Gimage
A PHP library for easy image handling. 🖼
Stars: ✭ 148 (+26.5%)
Mutual labels:  crop, resize
downscale
Better image downscale with canvas.
Stars: ✭ 80 (-31.62%)
Mutual labels:  resize, crop
Mergi
go library for image programming (merge, crop, resize, watermark, animate, ease, transit)
Stars: ✭ 127 (+8.55%)
Mutual labels:  crop, resize
Sharp
High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
Stars: ✭ 21,131 (+17960.68%)
Mutual labels:  crop, resize
Php Image Resize
PHP library to resize, scale and crop images. Cloud solution available at:
Stars: ✭ 955 (+716.24%)
Mutual labels:  crop, resize
Nova Advanced Image Field
🌄📐 A Laravel Nova advanced image field with cropping and resizing using Cropper.js and Intervention Image
Stars: ✭ 67 (-42.74%)
Mutual labels:  crop, resize
Imaging
Imaging is a simple image processing package for Go
Stars: ✭ 4,023 (+3338.46%)
Mutual labels:  crop, resize
Lipo
👄 Free image manipulation API service built on top of Sharp (an alternative to Jimp, Graphics Magic, Image Magick, and PhantomJS)
Stars: ✭ 101 (-13.68%)
Mutual labels:  crop, resize
Bimg
Go package for fast high-level image processing powered by libvips C library
Stars: ✭ 1,394 (+1091.45%)
Mutual labels:  crop, resize
Kkbinlog
支持mysql、MongoDB数据变更订阅分发
Stars: ✭ 112 (-4.27%)
Mutual labels:  mongodb
Graphql Nodejs Hapi Api
How to set-up a powerful API with Nodejs, GraphQL, MongoDB, Hapi, and Swagger
Stars: ✭ 116 (-0.85%)
Mutual labels:  mongodb
Mern Boilerplate
Fullstack boilerplate with React, Redux, Express, Mongoose, Passport Local, JWT, Facebook and Google OAuth out of the box.
Stars: ✭ 112 (-4.27%)
Mutual labels:  mongodb
Decentraleyes
This repository has a new home: https://git.synz.io/Synzvato/decentraleyes
Stars: ✭ 1,452 (+1141.03%)
Mutual labels:  cdn
Yunban
fullstack movie & music proj(rebuilding)
Stars: ✭ 116 (-0.85%)
Mutual labels:  mongodb
Dtcqueuebundle
Symfony2/3/4/5 Queue Bundle (for background jobs) supporting Mongo (Doctrine ODM), Mysql (and any Doctrine ORM), RabbitMQ, Beanstalkd, Redis, and ... {write your own}
Stars: ✭ 115 (-1.71%)
Mutual labels:  mongodb

#CDN over MongoDb GridFs

Join the chat at https://gitter.im/olebedev/cdn

This utility can be used as stand alone Content Delivery Network, using MongoDB GridFs as backend file storage. It can be built from source code or installed as already compiled binaries.

Also it can be used as a thin file storage library for your projects, based on martini framework. For example, when you use one of the cloud platforms like Heroku, with ephemeral file system for application's instances and you have to save user's data.

Features

  • on the fly crop and resize for image/png and image/jpeg mimetypes
  • cache strategy, based on HTTP Last-Modified header
  • additional metadata for each file & aggregated statistic for it
  • forced HTTP Content-Disposition header with the file name, for download links(only if flag is specified, see below)
  • buckets(MongoDB collections) as separation level
  • file listings for buckets, queried by metadata or without

Examples

Let's assume that the process is already running and listening to default http://localhost:5000.

Uploading

$ curl -F field=@./books.jpg http://localhost:5000/example
{
  "error": null,
  "field":"/example/5364d634952b829316000001/books.jpg"
}

Uploading with metadata is realy simple - you only should specify it as GET parameters for uploading URL:

$ curl -F field=@./books.jpg "http://localhost:5000/example?userId=1&some_another_data=useful"
...

Getting

As expected, the URL for getting is:

http://localhost:5000/example/5364d634952b829316000001/books.jpg 

or

http://localhost:5000/example/5364d634952b829316000001

That means that the filename is not necessary.
For forsed downloading specify dl GET parameter:

http://localhost:5000/example/5364d634952b829316000001/books.jpg?dl

In this case the file will not be previewed in the browser.

Crop and Resize images

This works only for files with mimetypes image/png & image/jpeg! In another cases it feature will be ignored.

Specify GET parameters crop, scrop or resize for URL. Crop example:

http://localhost:5000/example/5364d634952b829316000001/books.jpg?crop=500

The value should contain one or two(separated by one non-digit character) integer as width and height in pixels. If height is not specified, it will be used width value. For example, value crop=500 will be interpreted as crop=500x500.

scrop, resize parameter works the same way.
scrop - is smart crop, based on smartcrop library.

WARNING! Smartcrop algorithm may take a long time.

Aggregation and the listing of files

To get storage usage information in bytes, based on saved metadata, GET it like this:

$ http://localhost:5000/example/_stats?userId=1
{
  "fileSize": 204789
}

If metadata is not specified, usage information will be received for the whole bucket.

To get the listing of files, based on saved metadata, GET it like this:

$ http://localhost:5000/example?userId=1
[
  "/5364d634952b829316000001/books.jpg"
]

If metadata is not specified, usage information will be received for the whole bucket.

Usage

As library for martini framework.

$ go get github.com/olebedev/cdn

Simple server.go file:

package main

import (
	"log"
	"net/http"
	"os"
	"github.com/go-martini/martini"
	"github.com/olebedev/cdn/lib"
	"labix.org/v2/mgo"
)

// Acceess handler
func Access(res http.ResponseWriter, req *http.Request) {
	// check session or something like this
}

// Set prefix for current collection name, of course, if need it
// It useful when you store another data in one database
func AutoPrefix(params martini.Params) {
	// 'coll' - parameter name, which is used
	params["coll"] = "cdn." + params["coll"]
	// Ok. Now, cdn will work with this prefix for all collections
}

func main() {
	m := martini.Classic()

	session, err := mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}
	session.SetMode(mgo.Monotonic, true)
	db := session.DB("cdn")
	m.Map(db)

	logger := log.New(os.Stdout, "\x1B[36m[cdn] >>\x1B[39m ", 0)
	m.Map(logger)

	m.Group("/uploads", 
		cdn.Cdn(cdn.Config{
			// Maximum width or height with pixels to crop or resize
			// Useful to high performance
			MaxSize:  1000,
			// Show statictics and the listing of files
			ShowInfo: true,
			// If true it send URL without collection name, like this:
			// {"field":"/5364d634952b829316000001/books.jpg", "error": null}
			TailOnly: true,
		}),
		// Access logic here
		Access,
		// On the fly prefix for collection
		AutoPrefix,
	)

	logger.Println("Server started at :3000")
	m.Run()
}

Let's start it!

$ go run server.go
[cdn] >> Server started at :3000

That's all. Now you have started CDN at http://localhost:3000/uploads/.

Installation as stand alone

If you want to build it from sources:

$ go get github.com/olebedev/cdn

If you don't know what is Golang, check releases page and download binaries for your platform. Untar it and type this:

$ ./cdn --help
Usage of ./cdn:
  -maxSize="1000": 
  -mongo.name="cdn": 
  -mongo.uri="localhost": 
  -port="5000": 
  -showInfo="true": 
  -tailOnly="false":
TODO:
  • handler for 206 HTTP Status for large file
  • cache(save to GridFs croppped & resized image files)
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].