thumbnail

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go thumbnail helpers

Turn JPEG, PNG, or the first frame of a GIF into a small image for a plugin display. These helpers use Go's standard image codecs; there is no native library or separate codec installation.

Requirement Details
Language Go 1.27.4+; use the Go SDK setup
Input Caller-supplied JPEG, PNG, or GIF bytes
Output A sampled image, PNG bytes, or a display-ready data URI
Dependencies Go SDK and standard-library codecs only

Get started

Add the Go SDK to your plugin, then import its thumbnail package:

import "github.com/StreamDockManager/Plugin-SDK/Go/thumbnail"

// Run in background work with your operation's context.
image, err := thumbnail.Decode(ctx, encodedBytes, 72, 72)

Check err before using the returned image.Image. Use Render when you want a display-ready PNG data URI rather than raw pixels:

result, err := thumbnail.Render(ctx, encodedBytes, 72, 72)
// result.DataURI, result.Width, result.Height

Choose a helper

Helper Result
Decode Decode and sample to the requested dimensions.
Fit / FitDecode Fit while preserving aspect ratio; FitDecode does not upscale.
PNG Encode RGBA8 pixels as PNG.
DataURI / Render Produce a display-ready PNG data URI.

Limits and memory

Setting Default
Encoded input 64 MiB
Source pixels 32,000,000
Output size 1–320 pixels per dimension
GIF frames First frame only
Sampling Top-left pixel of each cell, without EXIF rotation

The full source image is decoded before sampling. Memory use depends on the source, not only the output size. Cancellation is cooperative during reads, sampling, and publication; a codec may continue CPU work until its next check. Keep decoding off the event loop.

Override input limits per call, without changing the fixed output bound:

limits := thumbnail.DefaultLimits()
limits.MaxInputBytes = 128 << 20
limits.MaxSourcePixels = 64_000_000
result, err := thumbnail.Render(ctx, encodedBytes, 256, 256, limits)

Supply positive values. The same optional limits apply to Decode, Fit, and FitDecode. Match your HTTP/file read limit to the chosen decoder limit; these helpers do not download images.

Development check

From the SDK's Go/ directory:

go test ./thumbnail

Troubleshooting

Problem What to check
Decoding returns an error Check the format, input byte count, source dimensions, output dimensions, and cancellation context.
A small output still uses substantial memory Source decoding happens before sampling. Lower the source pixel limit and bound the input reader.
Image work delays button handling Schedule decoding as bounded background work, then apply the result on the plugin's owner loop.

Go SDK · Shared helper contracts · MIT license

Documentation

Overview

Package thumbnail provides bounded standard-library image decoding and sampling

Index

Constants

View Source
const MaxDimension = 320
View Source
const MaxInputBytes = 64 << 20
View Source
const MaxSourcePixels = 32_000_000

Variables

This section is empty.

Functions

func DataURI

func DataURI(ctx context.Context, source image.Image) (string, error)

Encode image pixels as a PNG data URI

func Decode

func Decode(ctx context.Context, data []byte, width, height int, options ...Limits) (image.Image, error)

Decode retains a bounded full source image while producing an RGBA thumbnail Cancellation is cooperative at reads, sample rows, and result publication

func Fit

func Fit(width, height, maxWidth, maxHeight int, options ...Limits) (int, int, error)

Fit preserves aspect ratio, rounds down with a one-pixel minimum, and never upscales

func FitDecode

func FitDecode(ctx context.Context, data []byte, maxWidth, maxHeight int, options ...Limits) (image.Image, error)

Decode an image without upscaling beyond its source dimensions

func PNG

func PNG(ctx context.Context, source image.Image) ([]byte, error)

Encode image pixels as PNG with cancellation checks

Types

type Limits

type Limits struct {
	MaxInputBytes   int
	MaxSourcePixels int64
}

Limits bounds encoded input and decoded dimensions for one call Start with DefaultLimits when overriding a single field. Larger limits can increase codec memory use; limits must be positive safe integers

func DefaultLimits

func DefaultLimits() Limits

Return the default encoded-byte and source-pixel limits

type Rendered

type Rendered struct {
	Width, Height int
	DataURI       string
}

func Render

func Render(ctx context.Context, data []byte, maxWidth, maxHeight int, options ...Limits) (Rendered, error)

Decode, aspect-fit and encode a display-ready thumbnail

Jump to

Keyboard shortcuts

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