image

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 18 Imported by: 2 modules, 1 package

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 image 将单页图片、多页 TIFF 和 ZIP 图片包导入为带图片与 OCR 文字层的 OFD。

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(ctx context.Context, input any, output io.Writer, options ...Option) error

Convert 将 PNG/JPEG 或经典 TIFF 写成 OFD;TIFF 按 IFD 顺序展开。 ZIP 图片包应使用 ConvertZIP,不会作为普通图片自动解包。

func ConvertZIP added in v0.2.2

func ConvertZIP(ctx context.Context, input any, output io.Writer, options ...Option) error

ConvertZIP 将 ZIP 内的 PNG/JPEG/TIFF 按完整相对路径自然排序写成 OFD。 多页 TIFF 在对应文件位置连续展开;选项与 Convert 相同。

Example
package main

import (
	"archive/zip"
	"bytes"
	"context"
	"fmt"

	stdimage "image"
	"image/png"

	imageimport "github.com/zc310/ofd/pkg/converter/import/image"
)

func main() {
	var picture, input, output bytes.Buffer
	_ = png.Encode(&picture, stdimage.NewRGBA(stdimage.Rect(0, 0, 40, 30)))
	writer := zip.NewWriter(&input)
	for _, name := range []string{"10.png", "2.png", "1.png"} {
		part, _ := writer.Create(name)
		_, _ = part.Write(picture.Bytes())
	}
	_ = writer.Close()
	err := imageimport.ConvertZIP(context.Background(), input.Bytes(), &output,
		imageimport.WithOCR(false),
		imageimport.WithMaxArchiveEntries(10),
		imageimport.WithMaxEntryBytes(1<<20),
		imageimport.WithMaxTotalBytes(3<<20))
	fmt.Println(err == nil && bytes.HasPrefix(output.Bytes(), []byte("PK")))
}
Output:
true

Types

type Importer

type Importer struct {
	NameValue       string
	ExtensionsValue []string
}

Importer 是 converter 注册表使用的图片导入器。

func (*Importer) Extensions

func (i *Importer) Extensions() []string

func (*Importer) Import

func (i *Importer) Import(input any, output io.Writer, conv *converter.Converter) error

func (*Importer) MIME

func (i *Importer) MIME() string

func (*Importer) Name

func (i *Importer) Name() string

type Option

type Option func(*Options)

Option 修改导入选项。

func WithDPI

func WithDPI(dpi float64) Option

func WithMaxArchiveEntries added in v0.2.2

func WithMaxArchiveEntries(value int) Option

WithMaxArchiveEntries 设置 ZIP 的最大条目数,含被忽略的条目。

func WithMaxEntryBytes added in v0.2.2

func WithMaxEntryBytes(value int64) Option

WithMaxEntryBytes 设置 ZIP 单条目解压字节上限。

func WithMaxInputBytes

func WithMaxInputBytes(value int64) Option

func WithMaxPagePixels

func WithMaxPagePixels(value int64) Option

func WithMaxPages

func WithMaxPages(value int) Option

func WithMaxTotalBytes added in v0.2.2

func WithMaxTotalBytes(value int64) Option

WithMaxTotalBytes 设置 ZIP 累计解压字节上限。

func WithMaxTotalPixels

func WithMaxTotalPixels(value int64) Option

func WithMinConfidence

func WithMinConfidence(value float64) Option

func WithOCR

func WithOCR(enabled bool) Option

func WithOCREngine

func WithOCREngine(engine ocr.Engine) Option

func WithOCRLanguage

func WithOCRLanguage(language string) Option

func WithTextMode

func WithTextMode(mode TextMode) Option

type Options

type Options struct {
	Engine            ocr.Engine
	OCRLanguage       string
	DPI               float64
	TextMode          TextMode
	MinConfidence     float64
	MaxPages          int
	MaxPagePixels     int64
	MaxTotalPixels    int64
	MaxInputBytes     int64
	MaxArchiveEntries int
	MaxEntryBytes     int64
	MaxTotalBytes     int64
}

Options 控制图片导入和 OCR。

type TextMode

type TextMode string

TextMode 控制 OCR 文字层的视觉呈现。

const (
	// TextInvisible 让文字层透明,保留搜索和复制能力。
	TextInvisible TextMode = "invisible"
	// TextVisible 显示文字层,适合调试 OCR 坐标。
	TextVisible TextMode = "visible"
	// TextOff 不执行 OCR,也不生成文字层。
	TextOff TextMode = "off"
)

Jump to

Keyboard shortcuts

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