heic2jpgto convert HEIC files to JPG preserving exif
go get github.com/huydq189/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
package main
import (
"bytes"
"image/jpeg"
"io/ioutil"
"log"
"github.com/huydq189/goheif"
)
const jpegExtension = "jpeg"
const heifType = "image/heif"
const heicType = "image/heic"
// ConvertHeifToJpeg - If image file is Heif then convert it to Jpeg image file ortherwise return it's self
func ConvertHeifToJpeg(contentType, extension string) error {
if contentType == heicType || contentType == heifType {
goheif.SafeEncoding = true
buffer, _ := ioutil.ReadFile("sample1.heif")
img, err := goheif.Decode(bytes.NewReader(buffer))
if err != nil {
log.Println("Failed to decode heif file:", err)
return err
}
newBuf := new(bytes.Buffer)
err = jpeg.Encode(newBuf, img, nil)
if err != nil {
log.Println("Failed to encode to jpeg file:", err)
return err
}
ioutil.WriteFile("sample1.jpeg", newBuf.Bytes(), 0644)
return nil
}
return nil
}
func main() {
ConvertHeifToJpeg(heifType, jpegExtension)
}
-
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
-
A Utility
heic2jpgto illustrate the usage.
-
heif and libde265 are in their own licenses
-
goheif.go, libde265 golang binding and the
heic2jpgutility are in MIT license
- heif parser by @bradfitz (https://github.com/go4org/go4/tree/master/media/heif)
- libde265 (https://github.com/strukturag/libde265)
- implementation learnt from libheif (https://github.com/strukturag/libheif)
- Upstream the changes to heif?