Skip to content

Commit

Permalink
Usage docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MaestroError committed Jun 2, 2023
1 parent db4e346 commit bab8602
Showing 1 changed file with 76 additions and 7 deletions.
83 changes: 76 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# go-libheif
GoLang wrapper for the libheif library, providing easy-to-use APIs for HEIC to JPEG/PNG conversions and vice versa.
GoLang wrapper for the libheif library, providing easy-to-use APIs for HEIC to JPEG/PNG conversions and vice versa. (Also provides support for AVIF to JPEG/PNG conversions)

### Pre-requisites
You need to install [libheif](https://github.com/strukturag/libheif) before using this module. You can check the [strukturag/libheif](https://github.com/strukturag/libheif) for installation instructions, but as I have found, the easiest way for me was to use [brew](https://brew.sh/):
Expand All @@ -15,11 +15,80 @@ go get github.com/MaestroError/go-libheif
```

### Usage
...
This library provides functions to convert images between HEIC format and other common formats such as JPEG and PNG.

To convert an image from HEIC / HEIF / AVIF to JPEG or PNG:
```go
package main

import (
"log"

"github.com/MaestroError/go-libheif"
)

func main() {
err := go_libheif.HeifToJpeg("input.heic", "output.jpeg", 80)
if err != nil {
log.Fatal(err)
}

err = go_libheif.HeifToPng("input.heic", "output.png")
if err != nil {
log.Fatal(err)
}
}

```

To convert an image from JPEG or PNG to HEIC:
```go
package main

import (
"log"

"github.com/MaestroError/go-libheif"
)

func main() {
err := go_libheif.ImageToHeif("input.jpeg", "output.heic")
if err != nil {
log.Fatal(err)
}
}

```
*Note: It finds hard to convert some jpeg and png files to heic, see libheif_test.go:14 for details*

To save an image as HEIC:
```go
package main

import (
"image"
"log"

"github.com/MaestroError/go-libheif"
)

func main() {
img := image.NewRGBA(image.Rect(0, 0, 100, 100))
err := go_libheif.SaveImageAsHeif(img, "png", "output.heic")
if err != nil {
log.Fatal(err)
}
}

```
*Note: Quality for **HeifToJpeg** function and image format for **SaveImageAsHeif** function should be provided. The quality value ranges from 1 to 100 inclusive, higher values meaning better quality. The format for **SaveImageAsHeif** is the format of the original image.*

Please consult the GoDoc documentation for more detailed information about the provided functions and their usage.


##### ToDo
- Refactor the functions to return errors instead +
- Add documentation and examples for each function +
- Write tests at least for the Public functions +
- Write usage documentation
- Write guide article for module
- Write usage documentation +
- Write guide article for module
- Add contribution section in readme
- Implement the module in [php-heic-to-jpg](https://github.com/MaestroError/php-heic-to-jpg)
- Add credits section in readme and update in php-heic-to-jpg

0 comments on commit bab8602

Please sign in to comment.