cgbi

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: MIT Imports: 11 Imported by: 1

README

png cgbi

Xcode PNG compression (CgBI) in golang

Usage:

ipa's png to png file

func ToPNG(r io.Reader,w io.Writer) error {
    pic, _ := cgbi.Decode(r)
    return png.Encode(w, pic)
}

png file to ipa's png

func ToCgBI(r io.Reader, w io.Writer) error {
	m, _ := png.Decode(r)
	return cgbi.Encode(w, m)
}

Example

package main

import (
	"fmt"
	cgbi "github.com/928799934/go-png-cgbi"
	"image/png"
	"io"
	"io/ioutil"
	"os"
)

func main() {
	f1, err := os.Open("./AppIcon60x60@3x.png")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f1.Close()
	f2, err := ioutil.TempFile("./", "*.png")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f2.Close()
	fmt.Println(ToPNG(f1,f2))

	f3, err := os.Open("./026026565.png")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f3.Close()
	f4, err := ioutil.TempFile("./", "*_cgbi.png")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f4.Close()
	fmt.Println(ToCgBI(f3,f4))
}

func ToCgBI(r io.Reader, w io.Writer) error {
	m, _ := png.Decode(r)
	return cgbi.Encode(w, m)
}

func ToPNG(r io.Reader,w io.Writer) error {
	pic, _ := cgbi.Decode(r)
	return png.Encode(w, pic)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

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

Decode reads a PNG image from r and returns it as an image.Image. The type of Image returned depends on the PNG contents.

func DecodeConfig

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

DecodeConfig returns the color model and dimensions of a PNG image without decoding the entire image.

func Encode

func Encode(w io.Writer, m image.Image) error

Encode writes the Image m to w in PNG format. Any Image may be encoded, but images that are not image.NRGBA might be encoded lossily.

Types

type FormatError

type FormatError string

A FormatError reports that the input is not a valid PNG.

func (FormatError) Error

func (e FormatError) Error() string

type UnexpectedError

type UnexpectedError string

An UnexpectedError reports that the input uses a valid but unimplemented PNG feature.

func (UnexpectedError) Error

func (e UnexpectedError) Error() string

type UnsupportedError

type UnsupportedError string

An UnsupportedError reports that the input uses a valid but unimplemented PNG feature.

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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