Documentation
¶
Index ¶
- Constants
- Variables
- func ContentPartFromBytes(raw []byte, mime string, fileName string, cache *Cache) (model.ContentPart, error)
- func ExtractClipboardImage() ([]byte, string, error)
- func IsImagePath(path string) bool
- func Key(data []byte) string
- func LoadAsContentPart(absPath string) (model.ContentPart, error)
- func LoadAsContentPartCached(absPath string, cache *Cache) (model.ContentPart, error)
- func MimeTypeForPath(path string) (string, bool)
- type Cache
- type ResizeResult
Constants ¶
const ( // MaxResizeWidth is the maximum width before downscaling. MaxResizeWidth = 2048 // MaxResizeHeight is the maximum height before downscaling. MaxResizeHeight = 768 )
const MaxImageBytes = 20 * 1024 * 1024
MaxImageBytes is the maximum file size allowed for image loading (20MB).
Variables ¶
var SupportedExtensions = map[string]string{
".png": "image/png",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".gif": "image/gif",
".webp": "image/webp",
}
SupportedExtensions maps file extensions to their MIME types.
Functions ¶
func ContentPartFromBytes ¶
func ContentPartFromBytes(raw []byte, mime string, fileName string, cache *Cache) (model.ContentPart, error)
ContentPartFromBytes creates a ContentPart from raw image bytes, resizing if needed and caching the result.
func ExtractClipboardImage ¶
ExtractClipboardImage checks the Linux clipboard for image data using xclip. Returns (data, mimeType, nil) on success, (nil, "", nil) if no image, or (nil, "", err) on failure.
func IsImagePath ¶
IsImagePath returns true if the file path has a recognized image extension.
func LoadAsContentPart ¶
func LoadAsContentPart(absPath string) (model.ContentPart, error)
LoadAsContentPart reads an image file from disk and returns it as a ContentPart. No caching or resizing is applied.
func LoadAsContentPartCached ¶
func LoadAsContentPartCached(absPath string, cache *Cache) (model.ContentPart, error)
LoadAsContentPartCached reads an image file, resizes if needed, and returns a cached ContentPart. If cache is nil, behaves like LoadAsContentPart with resize applied.
func MimeTypeForPath ¶
MimeTypeForPath returns the MIME type for a recognized image file path.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is an LRU cache for processed image ContentParts. The cache key is the SHA-1 hex digest of the raw image bytes.
type ResizeResult ¶
ResizeResult holds the output of ResizeIfNeeded.
func ResizeIfNeeded ¶
func ResizeIfNeeded(data []byte, srcMime string) (ResizeResult, error)
ResizeIfNeeded decodes the image, downscales it if it exceeds the max dimensions, and re-encodes it. If the image is within bounds the original data is returned unchanged.