Documentation
¶
Overview ¶
Package image 将单页图片、多页 TIFF 和 ZIP 图片包导入为带图片与 OCR 文字层的 OFD。
Index ¶
- func Convert(ctx context.Context, input any, output io.Writer, options ...Option) error
- func ConvertZIP(ctx context.Context, input any, output io.Writer, options ...Option) error
- type Importer
- type Option
- func WithDPI(dpi float64) Option
- func WithMaxArchiveEntries(value int) Option
- func WithMaxEntryBytes(value int64) Option
- func WithMaxInputBytes(value int64) Option
- func WithMaxPagePixels(value int64) Option
- func WithMaxPages(value int) Option
- func WithMaxTotalBytes(value int64) Option
- func WithMaxTotalPixels(value int64) Option
- func WithMinConfidence(value float64) Option
- func WithOCR(enabled bool) Option
- func WithOCREngine(engine ocr.Engine) Option
- func WithOCRLanguage(language string) Option
- func WithTextMode(mode TextMode) Option
- type Options
- type TextMode
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
Convert 将 PNG/JPEG 或经典 TIFF 写成 OFD;TIFF 按 IFD 顺序展开。 ZIP 图片包应使用 ConvertZIP,不会作为普通图片自动解包。
func ConvertZIP ¶ added in v0.2.2
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 ¶
Importer 是 converter 注册表使用的图片导入器。
func (*Importer) Extensions ¶
type Option ¶
type Option func(*Options)
Option 修改导入选项。
func WithMaxArchiveEntries ¶ added in v0.2.2
WithMaxArchiveEntries 设置 ZIP 的最大条目数,含被忽略的条目。
func WithMaxEntryBytes ¶ added in v0.2.2
WithMaxEntryBytes 设置 ZIP 单条目解压字节上限。
func WithMaxInputBytes ¶
func WithMaxPagePixels ¶
func WithMaxPages ¶
func WithMaxTotalBytes ¶ added in v0.2.2
WithMaxTotalBytes 设置 ZIP 累计解压字节上限。