goheif

package module
v0.0.0-...-babb642 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 9 Imported by: 24

README

GoHeif - A go gettable decoder/converter for HEIC/AVIF based on libde265/dav1d

Install

  • heic2jpg to convert HEIC files to JPG preserving exif

go get github.com/jdeng/goheif/...

  • Tested

    • Mac OS X (High Sierra)
    • Linux (Ubuntu 16.04 / GCC 5.4)
    • Windows 7 64bit with TDM-GCC 32 (GCC 5.1) and golang 1.12 windows/386
  • Code Sample

func main() {
	flag.Parse()
	...
  
	fin, fout := flag.Arg(0), flag.Arg(1)
	fi, err := os.Open(fin)
	if err != nil {
		log.Fatal(err)
	}
	defer fi.Close()

	exif, err := goheif.ExtractExif(fi)
	if err != nil {
		log.Printf("Warning: no EXIF from %s: %v\n", fin, err)
	}

	img, err := goheif.Decode(fi)
	if err != nil {
		log.Fatalf("Failed to parse %s: %v\n", fin, err)
	}

	fo, err := os.OpenFile(fout, os.O_RDWR|os.O_CREATE, 0644)
	if err != nil {
		log.Fatalf("Failed to create output file %s: %v\n", fout, err)
	}
	defer fo.Close()

	w, _ := newWriterExif(fo, exif)
	err = jpeg.Encode(w, img, nil)
	if err != nil {
		log.Fatalf("Failed to encode %s: %v\n", fout, err)
	}

	log.Printf("Convert %s to %s successfully\n", fin, fout)
}

What is done

  • Changes make to @bradfitz's (https://github.com/bradfitz) golang heif parser

    • Some minor bugfixes
    • A few new box parsers, noteably 'iref' and 'hvcC'
  • Include libde265's source code (SSE by default enabled) and a simple golang binding

  • Include dav1d's source code and a simple golang binding

  • A Utility heic2jpg to illustrate the usage.

License

  • heif and libde265 are in their own licenses
  • dav1d is in its own license
  • goheif.go, libde265 golang binding and the heic2jpg utility are in MIT license

Credits

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SafeEncoding bool = true

SafeEncoding uses more memory but seems to make the library safer to use in containers.

Functions

func Decode

func Decode(r io.Reader) (image.Image, error)

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

func ExtractExif

func ExtractExif(ra io.ReaderAt) ([]byte, error)

Types

This section is empty.

Directories

Path Synopsis
cmd
heic2jpg command
Package heif reads HEIF containers, as found in Apple HEIC/HEVC images.
Package heif reads HEIF containers, as found in Apple HEIC/HEVC images.
bmff
Package bmff reads ISO BMFF boxes, as used by HEIF, etc.
Package bmff reads ISO BMFF boxes, as used by HEIF, etc.

Jump to

Keyboard shortcuts

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