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. The default, from safehttp, only
// connects to public addresses, so a listed host that resolves to the
// app's own network, or redirects there, is refused; pass a client of
// your own for originals on a private network.
HTTPClient *http.Client
}
Options configure the plugin.
Click to show internal directories.
Click to hide internal directories.