Categorygithub.com/olahol/go-imageupload
modulepackage
1.0.1
Repository: https://github.com/olahol/go-imageupload.git
Documentation: pkg.go.dev

# README

go-imageupload

GoDoc

:white_square_button: Gracefully handle image uploading and thumbnail creation.

Install

go get github.com/olahol/go-imageupload

Example

Thumbnail creator.

package main

import (
	"net/http"

	"github.com/olahol/go-imageupload"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, "index.html")
	})

	http.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "POST" {
			http.NotFound(w, r)
			return
		}

		img, err := imageupload.Process(r, "file")

		if err != nil {
			panic(err)
		}

		thumb, err := imageupload.ThumbnailPNG(img, 300, 300)

		if err != nil {
			panic(err)
		}

		thumb.Write(w)
	})

	http.ListenAndServe(":5000", nil)
}
<html>
<body>
  <form method="POST" action="/upload" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit">
  </form>
</body>
</html>

Contributors

  • Ola Holmström (@olahol)
  • Shintaro Kaneko (@kaneshin)

Documentation

# Packages

No description provided by the author

# Functions

Limit the size of uploaded files, put this before imageupload.Process.
Process uploaded file into an image.
Create JPEG thumbnail.
Create PNG thumbnail.

# Structs

No description provided by the author