github cshum/imagor v1.3.2

latest releases: v1.9.5, v1.9.4, v1.9.3...
3 years ago

Utility Filters

v1.3 introduces utility filters, which do not manipulate images but provide useful utilities to the imagor pipeline:

  • attachment(filename) returns attachment in the Content-Disposition header, and the browser will open a "Save as" dialog with filename. When filename not specified, imagor will get the filename from the image source
  • expire(timestamp) adds expiration time to the content. timestamp is the unix milliseconds timestamp, e.g. if content is valid for 30s then timestamp would be Date.now() + 30*1000 in JavaScript.
  • preview() skips the result storage even if result storage is enabled. Useful for conditional caching

Go Library

v1.3 also makes imagor more convenient to be used as a Go library.

See example below and also examples folder for various ways you can use imagor:

package main

import (
	"context"
	"github.com/cshum/imagor"
	"github.com/cshum/imagor/imagorpath"
	"github.com/cshum/imagor/loader/httploader"
	"github.com/cshum/imagor/vips"
	"io"
	"os"
)

func main() {
	app := imagor.New(
		imagor.WithUnsafe(true),
		imagor.WithLoaders(httploader.New()),
		imagor.WithProcessors(vips.NewProcessor()),
	)
	ctx := context.Background()
	if err := app.Startup(ctx); err != nil {
		panic(err)
	}
	defer app.Shutdown(ctx)
	blob, err := app.Serve(ctx, imagorpath.Params{
		Unsafe: true,
		Image:  "https://raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png",
		Width:  500,
		Height: 500,
		Smart:  true,
		Filters: []imagorpath.Filter{
			{"fill", "white"},
			{"format", "jpg"},
		},
	})
	if err != nil {
		panic(err)
	}
	reader, _, err := blob.NewReader()
	if err != nil {
		panic(err)
	}
	defer reader.Close()
	file, err := os.Create("gopher.jpg")
	if err != nil {
		panic(err)
	}
	defer file.Close()
	if _, err := io.Copy(file, reader); err != nil {
		panic(err)
	}
}

What's Changed

  • fix accidental copy paste network blocking flag descriptions by @thomasf in #242
  • feat(imagor): expire(timstamp) filter by @cshum in #245
  • fix(vips): apply focal filter for default resizing by @cshum in #249
  • fix(imagor): fix blob.ReadAll() buf size on error by @cshum in #250
  • feat(vips): focal point filter focal(x,y) by @cshum in #251
  • feat(imagor): imagor.Serve method by @cshum in #253
  • feat(imagor): imagor.ServeBlob by @cshum in #254
  • fix(imagor): imagor.Serve ensure path generated by @cshum in #255

Full Changelog: v1.2.4...v1.3.2

Don't miss a new imagor release

NewReleases is sending notifications on new releases.