Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
/ magicimage Public archive

magicimage is a simple image validation & save with rich feature package for net/http

License

Notifications You must be signed in to change notification settings

IndominusByte/magicimage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

PkgGoDev Test Coverage Status Go Report Card

go get github.com/IndominusByte/magicimage

Usage examples

A few usage examples can be found below. See the documentation for the full list of supported functions.

Validation Single Image

var SingleImage http.HandlerFunc = func(rw http.ResponseWriter, r *http.Request) {
  r.ParseMultipartForm(32 << 20)

	magic := magicimage.New(r.MultipartForm)

  // magic.Required = false
  // magic.MaxFileSize = 4 << 20 (4MB)

	if err := magic.ValidateSingleImage("file"); err != nil {
		fmt.Fprint(rw, err)
		return
	}

  magic.SaveImages(200, 200, "out/this-is-slug", true)
  // all filename
  fmt.Println(magic.FileNames)

	fmt.Fprint(rw, "success")
}

Validation Multiple Image

var MultipleImage http.HandlerFunc = func(rw http.ResponseWriter, r *http.Request) {
  r.ParseMultipartForm(32 << 20)

	magic := magicimage.New(r.MultipartForm)

  // magic.MinFileInSlice = 1
  // magic.MaxFileInSlice = 10

	if err := magic.ValidateMultipleImage("files"); err != nil {
		fmt.Fprint(rw, err)
		return
	}

  magic.SaveImages(200, 200, "out/this-is-slug", true)
  // all filename
  fmt.Println(magic.FileNames)

	fmt.Fprint(rw, "success")
}

About

magicimage is a simple image validation & save with rich feature package for net/http

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages