Documentation ¶
Overview ¶
Package thumbnailer provides a lightning fast and memory usage efficient thumbnailer via libvips and ffmpeg C bindings, with (external) MIME sniffing, and streaming I/O support. The formats available depend on the way libvips and ffmpeg are compiled.
Index ¶
- Variables
- func CreateThumbnail(file *File) error
- func CreateThumbnailWithContext(ctx context.Context, file *File) (err error)
- func DropAllVIPSCache()
- func InitVIPS()
- func MallocTrim(pad int) bool
- func Mallopt(param MalloptParam, value int) bool
- func PrintAllVIPSObjects()
- func SetFFmpegLogLevel(logLevel AVLogLevel)
- func SetVIPSOptions(options VIPSOptions)
- func ShutdownVIPS()
- type AVLogLevel
- type Dimensions
- type File
- type MalloptParam
- type ThumbError
- type Thumbnail
- type VIPSMemoryProfile
- type VIPSOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidData = avErrorToThumbError(avErrInvalidData) ErrFileFormatNotSupported = vipsErrorToThumbError(vipsError{ domain: "VipsForeignLoad", error: "the current build does not support this file format", }) )
Common ThumbErrors.
Functions ¶
func CreateThumbnail ¶
CreateThumbnail calls CreateThumbnailWithContext with a background context.
func CreateThumbnailWithContext ¶
CreateThumbnailWithContext creates a thumbnail from the supplied file (should go through FileFromReader, FromReadSeeker or FileFromPath and then ToWriter or ToPath, or equivalent for defined behaviour) and a context for interruption. Currently it's only checked if Done() in FFmpeg before blocking operations via an interrupt callback.
func DropAllVIPSCache ¶
func DropAllVIPSCache()
DropAllVIPSCache drops the whole operation cache. Called automatically on ShutdownVips(). Some VIPS versions can't run after this operation is performed.
func MallocTrim ¶
MallocTrim calls glibc's malloc_trim. Go refuses to return freed C memory to the OS otherwise for some reason.
func Mallopt ¶
func Mallopt(param MalloptParam, value int) bool
Mallopt calls glibc's mallopt. Reducing M_TOP_PAD or M_TRIM_THRESHOLD, increasing M_MMAP_THRESHOLD, and setting M_ARENA_MAX to GOMAXPROCS (it defaults to 8 * #threads), has shown good results with regards to freed memory "leaks".
func PrintAllVIPSObjects ¶
func PrintAllVIPSObjects()
PrintAllVIPSObjects prints all objects in vips's operation cache.
func SetFFmpegLogLevel ¶
func SetFFmpegLogLevel(logLevel AVLogLevel)
SetFFmpegLogLevel allows you to change the log level from the default (AVLogInfo).
func SetVIPSOptions ¶
func SetVIPSOptions(options VIPSOptions)
SetVIPSOptions initializes vips with options.
func ShutdownVIPS ¶
func ShutdownVIPS()
ShutdownVIPS shuts vips down. It can't be used again after this.
Types ¶
type AVLogLevel ¶
type AVLogLevel int
AVLogLevel defines the ffmpeg threshold for dumping information to stderr.
const ( AVLogQuiet AVLogLevel = (iota - 1) * 8 AVLogPanic AVLogFatal AVLogError AVLogWarning AVLogInfo AVLogVerbose AVLogDebug AVLogTrace )
Possible values for AVLogLevel.
type Dimensions ¶
type Dimensions struct {
Width, Height int
}
Dimensions stores the dimensions of the file and its thumbnail (if applicable).
type File ¶
type File struct { io.Reader io.Seeker Thumbnail mimemagic.MediaType Dimensions Orientation int Size int64 Duration time.Duration Title, Artist, Path string HasVideo, HasAudio, SeekEnd bool }
File stores the io.Reader and the io.Seeker or the path to the input file (preference to the path), its dimensions after analysis (if applicable), its Media Type, resultant thumbnail, size (completely optional for FFmpeg seeking), duration and the title and artist metadata if the file is a video or audio and those exist. Setting SeekEnd to false disables FFmpeg from seeking the end, which enables partial file reading in "semi-streaming" files (incomplete files that block until more data is available but have seeking capabilities) without blocking until the file is complete. HasVideo and HasAudio indicates that the file has video and/or audio streams, but having a video stream does not guarantee a thumbnail. Orientation corresponds to the EXIF orientation of the input file.
func FileFromPath ¶
FileFromPath takes a filepath and returns a File ready for supplying a thumbnail output via ToFile or ToPath.
func FileFromReadSeeker ¶
FileFromReadSeeker takes an io.ReadSeeker, a boolean seekEnd, and an optional filename (for better MIME sniffing), and returns a File ready for supplying a thumbnail output via ToFile or ToPath. Setting seekEnd to false disables FFmpeg from seeking the end, which enables partial file reading in "semi-streaming" files (incomplete files that block until more data is available but have seeking capabilities) without blocking until the file is complete. Setting it to true treats the ReadSeeker like a regular file.
func FileFromReader ¶
FileFromReader takes an io.Reader and an optional filename (for better MIME sniffing), and returns a File ready for supplying a thumbnail output via ToFile or ToPath. Without seeking, thumbnailing videos with non-sequential codecs (H.264 in some cases), will fail more than the alternatives.
func (*File) ToPath ¶
ToPath directs the thumbnailer to write the resultant thumbnail to the supplied path at the target bounding box size and quality (quality corresponds to libjpeg quality for JPEG thumbnails and to libimagequant quality for PNG thumbnails).
type MalloptParam ¶
type MalloptParam int
MalloptParam holds possible mallopt parameters.
const ( ArenaMax MalloptParam = C.M_ARENA_MAX ArenaTest MalloptParam = C.M_ARENA_TEST CheckAction MalloptParam = C.M_CHECK_ACTION MMapMax MalloptParam = C.M_MMAP_MAX MMapThreshold MalloptParam = C.M_MMAP_THRESHOLD MXFast MalloptParam = C.M_MXFAST Perturb MalloptParam = C.M_PERTURB TopPad MalloptParam = C.M_TOP_PAD TrimThreshold MalloptParam = C.M_TRIM_THRESHOLD )
All possible values of MalloptParam.
type ThumbError ¶
ThumbError stores the errors returned by the C Libraries used in this package.
func (*ThumbError) Error ¶
func (t *ThumbError) Error() string
type Thumbnail ¶
type Thumbnail struct { io.Writer Dimensions Quality, TargetDimensions int Path string HasAlpha, ThumbCreated bool }
Thumbnail stores the io.Writer to which to write the thumbnail, or creates it at the given path (preference to the path), its resultant dimensions, target Quality (both for JPEG and lossy PNG output), and the size of the bounding box to which the thumbnail is shrunk (TargetDimensions). HasAlpha indicates the image is a transparent PNG, JPEG if false. ThumbCreated indicates the thumbnail was created successfully.
type VIPSMemoryProfile ¶
VIPSMemoryProfile contains the vips memory profile.
func VIPSMemory ¶
func VIPSMemory() VIPSMemoryProfile
VIPSMemory returns vips's internal tracked memory profile.
type VIPSOptions ¶
VIPSOptions stores various options for vips.