images

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package images resizes remote images for <Image src="https://…">:

kit.WithPlugins(images.New(images.Options{Hosts: []string{"images.unsplash.com", "*.cdn.example.com"}}))

<Image src="https://images.unsplash.com/photo-123" width={800} height={600} alt="" />

<Image> asks /_tern/image?url=…&w=… for each width in its srcset. Only HTTPS images on the listed hosts are fetched, at most 20 MB and 50 megapixels; results are cached on disk. Images are re-encoded as JPEG, or PNG when they have transparency. (Imported images, with ?image, also get AVIF and WebP; Go has no pure-Go encoders for those.)

Index

Constants

View Source
const Path = "/_tern/image"

Path is where the plugin serves resized images.

Variables

View Source
var Widths = []int{64, 128, 256, 384, 640, 750, 828, 1080, 1200, 1920, 2048, 3840}

Widths are the widths <Image> requests; others are refused, which keeps the cache from filling with every possible size.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Hosts lists the hosts images may come from, such as
	// "images.unsplash.com" or "*.example.com" for its subdomains.
	Hosts []string
	// CacheDir keeps resized images; the default is a directory in the
	// system's temporary directory.
	CacheDir string
	// Quality is the JPEG quality; the default is 80.
	Quality int
	// MaxAge is how long browsers cache resized images; the default is a day.
	MaxAge time.Duration
	// HTTPClient fetches the originals.
	HTTPClient *http.Client
}

Options configure the plugin.

type Plugin

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

Plugin is the images plugin.

func New

func New(opts Options) *Plugin

New returns the plugin.

func (*Plugin) Name

func (*Plugin) Name() string

Name implements kit.Plugin.

func (*Plugin) ServeHTTP

func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Plugin) Setup

func (p *Plugin) Setup(s *kit.Setup) error

Setup implements kit.Plugin.

Jump to

Keyboard shortcuts

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