magicimage

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2022 License: MIT Imports: 15 Imported by: 0

README

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")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteFolderAndFile

func DeleteFolderAndFile(path string) error

remove dir or file and check if doesn't exists

func RenameFolderAndFile

func RenameFolderAndFile(old_path, new_path string) error

rename dir or file and check if doesn't exists

Types

type MagicImage

type MagicImage struct {
	MultipartForm  *multipart.Form
	AllowExt       []string
	MaxFileSize    int
	Required       bool
	DuplicateImage []uint64
	MinFileInSlice int
	MaxFileInSlice int
	Files          []*multipart.FileHeader
	FileNames      []string
}

func New

func New(MultipartForm *multipart.Form) *MagicImage

New returns a new blank MagicImage instance. By default the configuration is: - AllowExt: jpeg, png - MaxFileSize: 4 MB - Required: true

func (*MagicImage) SaveImages

func (magic *MagicImage) SaveImages(width, height int, path_upload string, square bool) error

save image for single image & multiple image with feature fix orientation iphone & create dir when doesn't exists.

func (*MagicImage) ValidateMultipleImage

func (magic *MagicImage) ValidateMultipleImage(key string) error

validator for multiple image with addon feature all image must be unique.

func (*MagicImage) ValidateSingleImage

func (magic *MagicImage) ValidateSingleImage(key string) error

validator for single image.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL