preview

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 16 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.

Documentation

Overview

Package preview 提供受限的图片预览、缩略图和独立 OFD 印章光栅化。

Index

Constants

View Source
const (
	// MaxImageBytes 限制光栅预览的输入和编码输出大小。
	MaxImageBytes = 8 << 20
	// MaxImagePixels 限制光栅预览完整解码前的像素数。
	MaxImagePixels = 25000000
)

Variables

View Source
var (
	ErrImageSize       = errors.New("图片文件超出预览限制")
	ErrImageFormat     = errors.New("仅支持预览 PNG 或 JPEG 图片")
	ErrImageDimensions = errors.New("图片尺寸超出预览限制")
	ErrRasterFormat    = errors.New("仅支持预览 PNG、JPEG、GIF、BMP、TIFF 或 WebP 光栅图片")
)
View Source
var ErrSealLimit = errors.New("OFD 印章超过预览限制(输入 8 MiB、2048 条目、解压 64 MiB、输出 8 MiB)")

Functions

func OFDSeal

func OFDSeal(ctx context.Context, data []byte, edge int, fallbackFamilies ...string) ([]byte, error)

OFDSeal 将印章子文档第一页光栅化为透明 PNG;不执行链接、动作或解锁嵌套文档。 edge 只允许缩略图 256 或大图 2048 像素,不代表盖章变换后的页面外观或验签结论。

Types

type Image

type Image struct {
	MIME string `json:"mime"`
	Data []byte `json:"data"`
}

Image 是经过格式和尺寸检查的只读图片预览。

func PNGJPEG

func PNGJPEG(data []byte) (Image, error)

PNGJPEG 按实际内容检查 PNG/JPEG 的文件大小和尺寸,不完整解码图片。

func Raster

func Raster(ctx context.Context, data []byte) (Image, error)

Raster 保留 PNG/JPEG 原图;其他光栅格式只解码第一帧/页,并限制 PNG 输出大小。

type Thumbnail

type Thumbnail struct {
	MIME   string `json:"mime"`
	Data   []byte `json:"data"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

Thumbnail 是长边不超过 256 像素的 PNG,Width/Height 保留原图尺寸。

func MakeThumbnail

func MakeThumbnail(ctx context.Context, data []byte) (Thumbnail, error)

MakeThumbnail 按光栅预览的输入安全限制完整解码并等比例缩小图片,不放大小图。

Jump to

Keyboard shortcuts

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