Documentation
¶
Index ¶
- func ConvertToHeif(srcPath string, dstPath string, opts ...EncoderOption) error
- func DecodeHeifToJpeg(heifPath string, jpegPath string, quality int) error
- func DecodeHeifToPng(heifPath string, pngPath string) error
- func EncodeImageAsHeif(img image.Image, path string, opts ...EncoderOption) error
- func HeifToJpeg(heifImagePath string, newJpegImagePath string, quality int) error
- func HeifToPng(heifImagePath string, newPngImagePath string) error
- func ImageToHeif(jpegOrPngImagePath string, newHeifImagePath string) error
- func ReturnImageFromHeif(filename string) (image.Image, error)
- func SaveImageAsHeif(i image.Image, format string, newHeifImagePath string) error
- func WebpToHeif(webpPath string, heifPath string, opts ...EncoderOption) error
- type Compression
- type EncoderOption
- type LogLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertToHeif ¶
func ConvertToHeif(srcPath string, dstPath string, opts ...EncoderOption) error
ConvertToHeif converts an image file at srcPath to HEIF format and saves it to dstPath.
The source format is auto-detected via image.Decode (supports JPEG, PNG, and any other format registered with the image package). Options are passed through to EncodeImageAsHeif.
Example:
err := ConvertToHeif("input.jpeg", "output.heic", WithQuality(70))
if err != nil {
log.Fatal(err)
}
func DecodeHeifToJpeg ¶
DecodeHeifToJpeg decodes a HEIF file and saves it as JPEG with the specified quality.
Quality must be between 1 and 100 inclusive; invalid values return an error. Both heifPath and jpegPath must be non-empty.
Example:
err := DecodeHeifToJpeg("input.heic", "output.jpg", 80)
if err != nil {
log.Fatal(err)
}
func DecodeHeifToPng ¶
DecodeHeifToPng decodes a HEIF file and saves it as PNG.
Both heifPath and pngPath must be non-empty.
Example:
err := DecodeHeifToPng("input.heic", "output.png")
if err != nil {
log.Fatal(err)
}
func EncodeImageAsHeif ¶
func EncodeImageAsHeif(img image.Image, path string, opts ...EncoderOption) error
EncodeImageAsHeif encodes an image.Image to HEIF format and saves it to the given path.
Options are applied in order using the Functional Options pattern. Defaults (quality=100, HEVC, lossless=true, LogLevelFull) are used when no options are provided.
Example:
img := image.NewRGBA(image.Rect(0, 0, 100, 100))
err := EncodeImageAsHeif(img, "output.heic", WithQuality(80), WithLossless(false))
if err != nil {
log.Fatal(err)
}
func HeifToJpeg ¶
HeifToJpeg converts an image from HEIF format to JPEG format.
This function takes the path to the input HEIF image file, the path where the output JPEG image file should be saved, and the quality of the output JPEG image.
Example:
err := HeifToJpeg("input.heic", "output.jpeg", 80)
if err != nil {
log.Fatal(err)
}
func HeifToPng ¶
HeifToPng converts an image from HEIF format to PNG format.
This function takes the path to the input HEIF image file and the path where the output PNG image file should be saved.
Example:
err := HeifToPng("input.heic", "output.png")
if err != nil {
log.Fatal(err)
}
func ImageToHeif ¶
ImageToHeif converts an image from JPEG or PNG format to HEIF format.
This function takes the path to the input JPEG or PNG image file and the path where the output HEIF image file should be saved.
Example:
err := ImageToHeif("input.jpeg", "output.heic")
if err != nil {
log.Fatal(err)
}
func ReturnImageFromHeif ¶
ReturnImageFromHeif decodes a HEIF file and returns the resulting image.
It expects the filename of a HEIF file as input. If the file cannot be decoded or the decoded image is not in HEIF format, an error is returned.
Example:
filename := "image.heic"
img, err := returnImageFromHeif(filename)
if err != nil {
log.Fatal(err)
}
func SaveImageAsHeif ¶
SaveImageAsHeif encodes an image in HEIF format and saves it to a file.
The image quality is set to 100, and lossless mode is enabled. The original image format is printed to the console.
Example:
img := image.NewRGBA(image.Rect(0, 0, 100, 100))
format := "png"
newHeifImagePath := "output.heif"
if err := SaveImageAsHeif(img, format, newHeifImagePath); err != nil {
log.Fatal(err)
}
func WebpToHeif ¶
func WebpToHeif(webpPath string, heifPath string, opts ...EncoderOption) error
WebpToHeif converts a WebP image file to HEIF format.
The source file must be a valid WebP image. Non-WebP files are rejected with a descriptive error naming the actual format detected. Options are passed through to EncodeImageAsHeif.
Importing this package registers the WebP decoder with Go's image package, enabling ConvertToHeif to also handle WebP files.
Example:
err := WebpToHeif("photo.webp", "photo.heic", WithQuality(80))
if err != nil {
log.Fatal(err)
}
Types ¶
type Compression ¶
type Compression int
Compression wraps heif.Compression to avoid direct dependency on CGo types in public API.
const ( CompressionHEVC Compression = iota CompressionAV1 CompressionAVC CompressionJPEG )
type EncoderOption ¶
type EncoderOption func(*encoderConfig)
EncoderOption configures an encoderConfig via the Functional Options pattern. Pass any number of EncoderOption values to encoding functions.
func WithCompression ¶
func WithCompression(compression Compression) EncoderOption
WithCompression returns an EncoderOption that sets the encoder compression type.
func WithLogging ¶
func WithLogging(logging LogLevel) EncoderOption
WithLogging returns an EncoderOption that sets the encoder log verbosity level.
func WithLossless ¶
func WithLossless(lossless bool) EncoderOption
WithLossless returns an EncoderOption that enables or disables lossless encoding.
func WithQuality ¶
func WithQuality(quality int) EncoderOption
WithQuality returns an EncoderOption that sets the encoder quality. Values are clamped silently: below 1 is set to 1, above 100 is set to 100.