gcf_go_image_resizer

package module
v0.0.0-...-aca0c19 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2019 License: MIT Imports: 8 Imported by: 0

README

Go Image Resizer Cloud Function

Pure Go Image Resizer function, deployable to Google Cloud Functions, using the disintegration/imaging package

Medium article: Image Resizing with Go and Cloud Functions

Original gopher image:
Big Gopher

Resized gopher image:
Small Gopher

Example gopher image generated using gopherize.me

Usage

https://{gcf-endpoint}/ResizeImage?url={url}&height={height}&width={width}

  • url: url of the image to resize
  • height: height of the output image in pixels
  • width: width of the output image in pixels

if width or height is missing, the aspect ratio is preserved

Deploying

$ gcloud functions deploy ResizeImage --runtime go111 --trigger-http

Local testing

There is an http server included in cmd/server.go allowing you to test locally

$ export GO111MODULE=on
$ go get -u
$ go run cmd/server/server.go

Todo

  • Add tests
  • Cache input images
  • Cache output images

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeImageToJpg

func EncodeImageToJpg(img *image.Image) (*bytes.Buffer, error)

encode image to jpeg

func FetchAndResizeImage

func FetchAndResizeImage(p *ResizerParams) (*image.Image, error)

fetch the image from provided url and resize it

func ResizeImage

func ResizeImage(w http.ResponseWriter, r *http.Request)

Cloud Function entry point

Types

type ResizerParams

type ResizerParams struct {
	// contains filtered or unexported fields
}

struct containing the initial query params

func NewResizerParams

func NewResizerParams(url string, height int, width int) ResizerParams

ResizerParams factory

func ParseQuery

func ParseQuery(r *http.Request) (*ResizerParams, error)

parse/validate the url params

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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